SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Case in where clause
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

pushp82
Yak Posting Veteran

83 Posts

Posted - 01/31/2013 :  01:17:25  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 01/31/2013 :  01:24:23  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.14 seconds. Powered By: Snitz Forums 2000