Click here to Skip to main content
15,897,334 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to implement searching dynamically,
for eg. I have 5 controls c1 is textbox, c2 is dropdownlists and c3,c4,c5 are dates
basic query is select * from abc
if there is data in c1 then add it to query’s where clause, else leave.
if there is data in c2 then add it to query’s where clause, else leave.
if there is data in c3 then add it to query’s where clause, else leave.
if there is data in c4 and c5 then add it to query’s where clause as date between c4 and c5, else leave.
User can give any value from c1 to c5 thus according to that i want to build query (i have to build proper where clause)
How do i perform it in SQL-server.
Posted
Updated 22-Feb-10 0:45am
v2

I think that this[^] article has your answer.
 
Share this answer
 
You can add them all to the query and use LIKE, you can also use an or as in if (txt1 = @val or LEN(@val) == 0). I once did a pretty complex search by just using or to ignore any search terms that were empty. I used the Trim method of the string class to not be passed any strings that were just whitespace.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900