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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 sql where case and select inside case

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2013-06-17 : 04:40:35
i want to query table, and on the where to do something like:
select...
Where
col1 in (case when @param1='' then select id from tbl2 else
col1)
And name like '%aaaa'
how can i do this?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-17 : 04:46:51
[code]
select...
Where
col1 in (select id from tbl2) or @param1 <> ''
[/code]


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2013-06-17 : 04:48:17
you missed the else point
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-17 : 04:53:20
i didnt. i replaced it with or. check and see the result

Where
(col1 in (select id from tbl2) or @param1 <> '')
And name like '%aaaa'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2013-06-17 : 05:11:10
ok 10X works.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-17 : 05:17:56
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -