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]));
开发者_StackOverflow社区
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]
精彩评论