Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
declare @a int;
set @a=1;

select * from vehicles where company in (
case when @a=1 then (3,4) else   (2)) end


this query is not working.. Can anyone help me
Posted

Might be this should work.

SQL
declare @a int
declare @str varchar(30)
declare @query varchar(500)

set @a=1

set @str = '2'

 if @a = 1
 begin
 set @str = '3,4'
 end

set @query = 'select * from vehicles where company in (' + @str + ')'

exec (@query)
 
Share this answer
 
Try this,
SQL
DECLARE @a INT;
SET @a=1;

SELECT * FROM vehicles
WHERE 1 = 
        (CASE 
              WHEN @a=1 AND company IN (3,4) THEN 1 
              WHEN @a=2 AND company=2 THEN 1 
         END)

Happy Coding!
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900