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 |
xpandre
Posting Yak Master
212 Posts |
Posted - 2013-12-10 : 12:58:13
|
I need a query like :declare @afilter varchar(100) = 'test'select top 10 * from table1where case when @afilter = 'test' then col1 = 'test' else col1!='test' endIts like : if @afilter is 'test' then return everything from the table which has col1 = 'test'else return records from table1 where col1!='test'Any help appreciated.ThanksSam |
|
xpandre
Posting Yak Master
212 Posts |
Posted - 2013-12-10 : 13:02:34
|
I did something like below..but I think its much more easier than this:(DECLARE @afilter VARCHAR (50) set @afilter='test'select top 10 * from (SELECT * , case when L1.col1 = 'test' then 1 else 0 end caseclientFrom table1 L1 )awhere case when @afilter='test' then 1 else 0 end =caseclient |
|
|
|
|
|