0

Hi
Just asking for a better solution for my approach in getting sql result with different multiple conditions based on comboboxes. I have a 4 comboboxes, for Branch, Type, Status and other info. User can select conditions from this comboboxes. The default value is "All", meaning no specific condition at all, but can choose from this cb's simultaneously. For example the user can choose specific type with all status and all other info, can also choose specific type, condition and all other info. in short he can select any combination of conditions from this cb's. I know I could query them individually but that would take me a lot of queries. Is there better approach for this

Thanks

3
Contributors
12
Replies
22
Views
3 Years
Discussion Span
Last Post by Lethugs
0

you want to fliter data from one combo box to another or can you put Sketch about your requirement

0

yes I want to filter data from one combobox to another. I have already storeproc, but the problem is f i make a default parameter for each condition, it will require a value even if the combobox is selected as 'All', which in that case no condition should be for that matter. The 'All' there is just a dummy selection which will show data now without condition. Every combobox represents different columns in my sql server

0

to clarify it further, example

Branch selected, Type = 1, Status and other info = All, the query would be

Select * from table where Branch=@branch and Type = 1

branch selected, Type =1, Status = Pending, Other info = all, the query would be

Select * from table where Branch=@branch and Type=1 and Status = 'Pending'

branch selected, Type = All, Status = Complete, Other Info = Sent, the query would be

Select * from table where Status = 'Complete' and OtherInfo = 'Sent'

and so on,

So there are different combination of conditions from those cb's. doing it per possible combinations would take a lot of queries. Any better solution for this?

thanks again

0

Im using diffrent parameters for each cb. Some are ID's and some are Text

0

One way or the other, you'll have to build your query. Whether you do it in code, or in the stored procedure, there's no getting around it.

0

So that means no better approach for this? Do i need to query it individually?

0

In my query like
Select * from table where Branch=@branch and Type=1 and Status = 'Pending'
ho will I remove @branch parameter if the user wants to include all branches? not putting a value will generate error asking for the value of parameter since it is already included in my select statement?

Thanks

0

Show your code, because I still don't know if you're using a stored procedure or a programming language.

0

Thanks for you guys for helping me, I did some revisions on my code. I declared a variable for my query, another variable for my conditions, then a just concatenate this variables depending on the conditions set by the user then pass this joined variable as my final query. It works for now since I have'nt encounter problems yet. Thanks again

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.