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 |
|
micnie_2020
Posting Yak Master
232 Posts |
Posted - 2011-10-14 : 04:36:19
|
| Hi all,I trying to do the sql if @ExportTy doesn't pass in 1 mean will never checking on this criteria BU.regname & DE.segmentHow can i do that? I try below code. Having issue on 1=1Please advise.Tq where .....AND Case when @ExportTy='0' then 1=1 else BU.regname in (@Region) endAND Case when @ExportTy='0' then 1=1 else DE.segment in (@Segment) end |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-14 : 04:37:51
|
| [code]...where .....1=1 or( ',' + @Region + ',' LIKE '%,' + BU.regname + ',%' and ',' + @Segment + ',' LIKE '%,' + DE.segment + ',%')[/code] ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
sshelper
Posting Yak Master
216 Posts |
Posted - 2011-10-15 : 00:55:03
|
| If I understood your question correctly, your WHERE clause will look something like this:WHERE (@ExportTy = 0 OR BU.regname IN (@Region)) AND (@ExportTy = 0 OR DE.segment IN (@Segment))SQL Server Helperhttp://www.sql-server-helper.com/error-messages/msg-1-500.aspx |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-15 : 02:07:25
|
quote: Originally posted by sshelper If I understood your question correctly, your WHERE clause will look something like this:WHERE (@ExportTy = 0 OR BU.regname IN (@Region)) AND (@ExportTy = 0 OR DE.segment IN (@Segment))SQL Server Helperhttp://www.sql-server-helper.com/error-messages/msg-1-500.aspx
you cant use variable in IN like this.You need to use dynamic sql or use LIKE as in suggestion before------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|