SQLserver儲存過程中in新增條件變數@A問題 動態變數
阿新 • • 發佈:2021-10-07
可以把@AAA存到一個表變數裡
參考示例: 本示例添加了2個 動態變數
DECLARE @DATE DATE; SET @DATE = GETDATE( ); DECLARE @TA TABLE(col nvarchar(4000)); DECLARE @TA2 TABLE(col nvarchar(4000)); declare @sql varchar(2000); declare @sql2 varchar(2000) set @sql='C2E2B864-,F45-08D84A19C12D,08D84A19C12D'; set @sql2='A6D3385B-'; declare @s varchar(4000); declare @s2 varchar(4000); set @sql=@sql+','; while charindex(',',@sql)>0 begin select @s=substring(@sql,1,charindex(',',@sql)-1) select @sql=substring(@sql,charindex(',',@sql)+1,len(@sql)) INSERT @TA VALUES(@s); end set @sql2=@sql2+','; while charindex(',',@sql2)>0 begin select @s2=substring(@sql2,1,charindex(',',@sql2)-1) select @sql2=substring(@sql2,charindex(',',@sql2)+1,len(@sql2)) INSERT @TA2 VALUES(@s2); end ;WITH /*xxxx*/ CurDayQDLF AS ( select * from OppID a where a.ParentID in (SELECT * FROM @TA) ), CurDayQDLF2 AS ( select * from OppID a where a.ParentID in (SELECT * FROM @TA2) ) select * from CurDayQDLF2
參考連結:
http://www.data700.com/2020/0326/85.html
紙上得來終覺淺,絕知此事要躬行。