Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
caterpillar
Starting Member
9 Posts |
Posted - 2006-08-03 : 12:19:41
|
| Hi all, i have made a SEARCH page with the following inputs: KEY WARD BLOCK ZONE TITLE SUBT *All fields are VARCHAR TYPE.I need to make a query such that whenever the user enters data, result comes, be it 1 input, all inputs or combination of inputs. This is working in all input fields, except for KEY & WARD. They are showing all records & not filtering as what is being selected.The query is written below, plz. suggest me something. -- shows comment SELECT DISTINCT FROM blah blah blah................ WHERE --CONTAINS(viewname.*,@SKey) ( (c.block LIKE '%' + @SKey +'%') or (c.zone LIKE '%' + @SKey +'%') ) or -- CONTAINS (c.*, '*@ward*') ((c.ward = @ward) or (ward <> '')) --- (c.ward LIKE '%' + @ward +'%') AND -- (@block = '') OR (c.block LIKE '%' + @block +'%') --(c.block = @block ) (c.block LIKE '%' + @block +'%') --AND ((@zone = '') OR (c.zone = @zone) AND( c.zone LIKE '%' + @zone +'%') -- or (@zone = '') --AND ((@title = '') OR ( c.co_title = @title) AND (c.title LIKE '%' + @title +'%') -- or (@title = '') --AND ((@subt = '') OR (c.co_subt = @subt) AND (c.subt LIKE '%' + @subt +'%') --or (@subt = '') I feel i need to place the ORs and ANDs properly. Plz. help me out! Regards Monica |
|
|
Srinika
Master Smack Fu Yak Hacker
1378 Posts |
Posted - 2006-08-03 : 12:25:31
|
| Build the string with the conditions and concat that with Where 1 = 1 as in :'Select ... Where 1 = 1 ' + @ConditionsStrSo that u don't have to write a lengthy AND-OR Logic Srinika |
 |
|
|
|
|
|