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

后端 未结 14 2073
心在旅途
心在旅途 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 05:04

    No, there is no such type. But there are some choices:

    • Dynamically generated queries (sp_executesql)
    • Temporary tables
    • Table-type variables (closest thing that there is to a list)
    • Create an XML string and then convert it to a table with the XML functions (really awkward and roundabout, unless you have an XML to start with)

    None of these are really elegant, but that's the best there is.

提交回复
热议问题