Hi there, I need help to write sql query for my search form, but I don't know how to write the sql command that can be used to display automatically by one, two or three criterias. Here is the form: IT should work like that: If I insert data in first field on the top of form it should show all date by that inserted data, but if I insert data in another form field it should filter by first field and by second field. If I insert data into first three fields it should show all data by all these three fields, but if I insert data into only third field it should show the list only for that third field data. HOW TO WRITE SQL COMMAND? Thanks
Since we OBVIOUSLY know nothing about your existing database this question can't be easily answered without assumption... You could use something similar to: SELECT some_col1, some_col2, some_col3 FROM Some_Table WHERE some_col1 = 'something' OR some_col_2 = 'something'; You could use LIKE 'blah%' to search non-exact matches. SELECT some_col1, some_col2, some_col3 FROM Some_Table WHERE some_col1 LIKE 'something%' OR some_col_2 LIKE 'something%';
Thank you, it really does not matter what database collumn is I need just the principle. I am programing on C# and already created a method.
It's not one SQL statement. Each time the user enters another field, you create a new SQL statement that uses all the fields entered so far. Then you fill in whatever gets filled in using the data returned by the query.
Yea, it is pretty simple if you have the syntax and the principle of each query. Glad you find your way .