How can I implement the where clause statement in the where clause?

You need to do the following:
stored procedure accepts @type int

select * from table as t where case @type when 1 then t.type = 1 when 2 then t.type != 1 when 3 then t.type = t.type 

ms sql server 2012

  • IMHO, the easiest way is to make 3 SELECTs in the appropriate IFs. - Yaant

2 answers 2

 declare @t table ([type] int) declare @type int insert into @t ([type]) values (0), (1), (2), (3), (4) set @type = 3 select * from @t as t where @type = case when @type = 3 then 3 when t.type = 1 then 1 when t.type <> 1 then 2 END 
  • And what else can be after type = 1 and type <> 1 checks? - Mike
  • Yes, it can not. corrected - Konst
  • Thanks, Konst. Works great - Justice
 select * from table as t where ( (@type=1 and t.type=1) or (@type=2 and t.type!=1) )