SQL query based upon some criteria


sir, it like searching at function

i need to search the table which has data stored in ms access table. i have create a text box for the contract no,username and date and need to search the table according to contract no or username or date.

for that i need a coding with solve the problem in single sql command. i have try it with where help is a table,search-test is form.

when the help(table).cont_no(field) is equal to search-test(form name).cont_no(text box field)

SELECT * FROM Help WHERE (((Help.cont_no)=[Forms]![search-test]![cont_no])) OR (((Help.username)=[Forms]![search-test]![username]) or ((Help.date)=[Forms]![search-test]![cbo_date]));

hope you will understand my view


I think I understand that you want to search based on any combination of those criteria. I suggest you try this:

SELECT * FROM Help WHERE ([Forms]![search-test]![cont_no] = '' OR Help.[cont_no]=[Forms]![search-test]![cont_no]) AND ([Forms]![search-test]![username] = '' OR Help.[username]=[Forms]![search-test]![username]) AND ([Forms]![search-test]![cbo_date] = '' OR Help.[date]=[Forms]![search-test]![cbo_date])

This query will search for a combination of your search boxes if you have entered values in them. If they are blank, they are excluded from the search criteria. You may need to adjust it as required for the "empty" status of your fields. I have assumed "empty" to be a blank string

UPDATE If you want to search for any combination of the criteria you can use OR clauses as follows:

SELECT * FROM Help WHERE Help.[cont_no]=[Forms]![search-test]![cont_no] OR Help.[username]=[Forms]![search-test]![username] OR Help.[date]=[Forms]![search-test]![cbo_date]


  • Basic defensive programming [duplicate]
  • It is possible use the same sql azure instance from two different cloud service of two different sub
  • TSQL Rolling Average of Time Groupings
  • distinct values from multiple fields within one table ORACLE SQL
  • TFS - how do I sum child task hours to parent
  • What is corresponding c++ data type to SQL numeric(18,0) data type?
  • Create function that can pass a parameter without making a new component
  • Alamofire and Reachability.swift not working on xCode8-beta5
  • How can we prepend rows to a react native list-view?
  • How can Delete be both a DDL and a DML statement
  • How to 'create temp table as select' in Slick?
  • Find group of records that match multiple values
  • How to make R's read_csv2() recognise the text characters properly
  • pyodbc doesn't report sql server error
  • Row Count Is Returning the incorrect number using RaptureXML
  • PHPUnit_Framework_TestCase class is not available. Fix… - Makegood , Eclipse
  • Sails.js/waterline: Executing waterline queries in toJSON function of a model?
  • Illegal mix of collations for operation for date/time comparison
  • PHP - How to update data to MySQL when click a radio button
  • Counter field in MS Access, how to generate?
  • How to redirect a user to a different server and include HTTP basic authentication credentials?
  • Running a C# exe file
  • Join two tables and save into third-sql
  • How to model a transition system with SPIN
  • Redux, normalised entities and lodash merge
  • Release, debug version and Authorization Google?
  • ORA-29908: missing primary invocation for ancillary operator
  • jQuery tmpl and DataLink beta
  • Do create extension work in single-user mode in postgres?
  • Run Powershell script from inside other Powershell script with dynamic redirection to file
  • using conditional logic : check if record exists; if it does, update it, if not, create it
  • SQL merge duplicate rows and join values that are different
  • KeystoneJS: Relationships in Admin UI not updating
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • Proper way to use connect-multiparty with express.js?
  • Getting error when using KSoap library to consume .NET web services
  • How to set the response of a form post action to a iframe source?
  • Hits per day in Google Big Query
  • Checking variable from a different class in C#
  • Converting MP3 duration time