SQL Server store multiple values in sql variable

后端 未结 6 903
春和景丽
春和景丽 2020-12-29 15:02

I have the following query:

select * 
from cars 
where make in (\'BMW\', \'Toyota\', \'Nissan\')

What I want to do is store the where param

6条回答
  •  旧时难觅i
    2020-12-29 15:11

    You can use a table variable:

    declare @caroptions table
    (
        car varchar(1000)
    )
    
    insert into @caroptions values ('BMW')
    insert into @caroptions values ('Toyota')
    insert into @caroptions values ('Nissan')
    
    select * from cars where make in (select car from @caroptions)
    

提交回复
热议问题