DECLARE @Status AS VARCHAR(400) SET @status = '''Closed'',''OPEN''' select * from MYTABLE where status in(@status)
虽然如此从MYTABLE中选择*,其中(‘Closed’,’Open’)中的状态会提取行
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