bug_x

导航

 

可以把@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

       https://www.cnblogs.com/lckblog/p/5320391.html

      https://stackoverflow.com/questions/37095177/using-if-begin-end-with-cte-incorrect-syntax-near-the-keyword-end 

 

posted on 2021-10-07 15:15  bug_x  阅读(390)  评论(0编辑  收藏  举报