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 2005 Forums
 Transact-SQL (2005)
 case statement

Author  Topic 

nsah382
Starting Member

2 Posts

Posted - 2011-11-14 : 09:33:00
I am trying to write a query. But I am getting a syntax error near 'or'. I must be doing something wrong.


declare @VALUATOR_TYPE varchar(5)
set @VALUATOR_TYPE ='v,i'

select * from dbo.Reports
where report_flags like (case @VALUATOR_TYPE
when 'v' then '%v%'
when 't' then '%t%'
when 'i' then '%i%'
when 'v,i' then '%v%' or '%i%'
when 'i,t' then '%i%' or '%t%'
end)




Please let me know the correct syntax.

Thanks and Regards,
Neel

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-11-14 : 09:53:34
case @VALUATOR_TYPE
when 'v' then '%v%'
when 't' then '%t%'
when 'i' then '%i%'
when 'v,i' then '%[vi]%'
when 'i,t' then '%[it]%'
end


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

nsah382
Starting Member

2 Posts

Posted - 2011-11-14 : 11:02:07
Thanks a ton..!!! it worked..

quote:
Originally posted by nigelrivett

case @VALUATOR_TYPE
when 'v' then '%v%'
when 't' then '%t%'
when 'i' then '%i%'
when 'v,i' then '%[vi]%'
when 'i,t' then '%[it]%'
end


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.



Thanks and Regards,
Neel
Go to Top of Page
   

- Advertisement -