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
 General SQL Server Forums
 New to SQL Server Programming
 Case in where clause

Author  Topic 

pushp82
Yak Posting Veteran

83 Posts

Posted - 2013-01-31 : 01:17:25
Hi Guys,

I'm jumbling around a "case syntax in where clause" from long time if someone could help me ASAP please....

declare @Type int
set @Type=1
select * from tbl_outlet ot
left join tbl_brand bn on bn.bnd_otl_id=ot.otl_id
where case @Type when 1 then ot.OTL_NAME like '%A' end

above syntax is returning error, I tried all possible syntax but failed:

Incorrect syntax near the keyword 'like'.

Please advice!
Pushp

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-31 : 01:24:23
case is not control flow statement. its just a conditional expression

so your condition have to be

declare @Type int
set @Type=1
select * from tbl_outlet ot
left join tbl_brand bn on bn.bnd_otl_id=ot.otl_id
where ot.OTL_NAME like case @Type when 1 then '%A' end



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -