为什么以下SQL不能给我任何东西
DECLARE @Status AS VARCHAR(400) SET @status = '''Closed'',''OPEN''' select * from MYTABLE where status in(@status)
虽然 select * from MYTABLE where status in('Closed','Open')吸引我的行
select * from MYTABLE where status in('Closed','Open')
您可以根据需要执行一些动态SQL,但我认为这并不是真正的竞争。
DECLARE @Status nVARCHAR(400), @SQL nvarchar(500) SET @status = '''Closed'''+','+'''OPEN''' set @SQL = ' select * from [MYTABLE] where status in('+@status +')' exec sp_executesql @SQL GO