Nested Select statement
-
Hi all I have an issue with select statement. Like in one form i have 5 fields all combo box and after selecting all we have search option so in a data grid i am displaying the records which satisfies all criteria in the combo box. It works fine. But now i want is if user select only one combo box and press search the grid should show the related records which satisfies the combo box condition. I have tried with AND OR condition in query but not getting the proper records. Pl help Regards
Prakash Mishra(Banglore,India)
-
Hi all I have an issue with select statement. Like in one form i have 5 fields all combo box and after selecting all we have search option so in a data grid i am displaying the records which satisfies all criteria in the combo box. It works fine. But now i want is if user select only one combo box and press search the grid should show the related records which satisfies the combo box condition. I have tried with AND OR condition in query but not getting the proper records. Pl help Regards
Prakash Mishra(Banglore,India)
There are several ways to solve this problem, I will suggest one of them here. If you have five parameters you need to set up your where clause to allow each of the parameters to be optional. All of this is done in the where clause. So the code would look like this if a parameter is being passed in then you need to set it to a default value. I will assume that all your parameters are strings. Where (param1 = '' or param1 = @param1) and (param2 = '' or param2 = @param2) and (param3 = '' or param3 = @param3) and (param4 = '' or param4 = @param4) and (param5 = '' or param5 = @param5) So the idea is if the user only selects one combo box, just set the rest of the parameters to '' and your query should work. Hope that helps. Ben
-
Hi all I have an issue with select statement. Like in one form i have 5 fields all combo box and after selecting all we have search option so in a data grid i am displaying the records which satisfies all criteria in the combo box. It works fine. But now i want is if user select only one combo box and press search the grid should show the related records which satisfies the combo box condition. I have tried with AND OR condition in query but not getting the proper records. Pl help Regards
Prakash Mishra(Banglore,India)
I was waiting for reply from 5 long hours but didn't got a single one at last i solved the problem of my own. for for others reference i am posting the solution select * from table name (must condition and 1st condition)or (must condition and 2nd condition)or (must condition and 3rd condition)....
Prakash Mishra(Banglore,India)
-
There are several ways to solve this problem, I will suggest one of them here. If you have five parameters you need to set up your where clause to allow each of the parameters to be optional. All of this is done in the where clause. So the code would look like this if a parameter is being passed in then you need to set it to a default value. I will assume that all your parameters are strings. Where (param1 = '' or param1 = @param1) and (param2 = '' or param2 = @param2) and (param3 = '' or param3 = @param3) and (param4 = '' or param4 = @param4) and (param5 = '' or param5 = @param5) So the idea is if the user only selects one combo box, just set the rest of the parameters to '' and your query should work. Hope that helps. Ben
Thanks Ben i solved the problem of my own at last from morning i was trying and didn't got any reply. I am new to sql, Regards
Prakash Mishra(Banglore,India)