Define variable to use with IN operator (T-SQL)

后端 未结 14 2063
心在旅途
心在旅途 2020-11-28 04:24

I have a Transact-SQL query that uses the IN operator. Something like this:

select * from myTable where myColumn in (1,2,3,4)

Is there a wa

14条回答
  •  自闭症患者
    2020-11-28 04:59

    Starting with SQL2017 you can use STRING_SPLIT and do this:

    declare @myList nvarchar(MAX)
    set @myList = '1,2,3,4'
    select * from myTable where myColumn in (select value from STRING_SPLIT(@myList,','))
    

提交回复
热议问题