using dynamic IN clause in MSSQL

前端 未结 2 1500
小蘑菇
小蘑菇 2020-12-20 20:01

Why the following SQL does not fetch me anything

DECLARE @Status AS VARCHAR(400)
SET @status = \'\'\'Closed\'\',\'\'OPEN\'\'\'
select * from MYTABLE where st         


        
2条回答
  •  温柔的废话
    2020-12-20 20:33

    Your first question checks if the value 'Closed','OPEN' exists in the database. The values is not expanded.

    If you use SQL Server 2008 or later you can use Table Valued Parameters to achieve the same thing.

提交回复
热议问题