DECLARE @IDS VARCHAR(20)
SELECT @IDS='1,2,31971'

DECLARE @SQL NVARCHAR(2000)
DECLARE @ISOVER BIT
DECLARE @ISEXECUTE BIT
DECLARE @SN VARCHAR(20)

SELECT @SQL='SELECT @SN=SN FROM tbClinicBill WHERE ID IN(​​'+@ids+')'​​​--执行动态生成的SQL语句
EXEC sp_executesql @SQL,
     ​​N'@sn​​ varchar(20) output',
     @SN out

PRINT @SN