Sql server 分配给变量“的值的类型”;用户:de_sters“;与当前变量类型不同
我有一个变量Sql server 分配给变量“的值的类型”;用户:de_sters“;与当前变量类型不同,sql-server,ssis,Sql Server,Ssis,我有一个变量de_sters,一个字符串类型的变量,正如在我的SSIS包中定义的,它的作用域是SSIS包,我需要使用执行Sql任务包,用一个表中的几行值来填充它 底线是我有一个“执行Sql任务”包,在proprities->“Sql语句”中我写了: declare @s varchar(max) = '' select @s = case when @s <> '' then @s + ',''' + employer_name + '''
de_sters
,一个字符串类型的变量,正如在我的SSIS包中定义的,它的作用域是SSIS包,我需要使用执行Sql任务
包,用一个表中的几行值来填充它
底线是我有一个“执行Sql任务”包,在proprities->“Sql语句”中我写了:
declare @s varchar(max) = ''
select @s = case when @s <> ''
then @s + ',''' + employer_name + ''''
else @s + '''' + employer_name+ ''''
end
from employers
select @s as Result
有任何帮助或提示吗?问题是SSIS不理解varchar(max)
作为数据类型。您需要指定限制。只需将max
值更改为8000
declare @s varchar(8000) = ''
如果字符串非常大,则在查询中使用FullResultSet和varchar(max)
,并将值存储在数据类型为object
的变量中
现在,为了访问对象,请使用脚本任务
或脚本组件
(数据流),并编写以下代码以从对象
变量中提取值
OleDbDataAdapter oleDA = new OleDbDataAdapter();
DataTable dt = new DataTable();
oleDA.Fill(dt, Dts.Variables["User::YourVariable"].Value);
foreach (DataRow rowLoop in dt.Rows)
{
MessageBox.Show (rowLoop[0].ToString());
}
要将controlflow
中SQL脚本任务
中的varchar(max)
字段加载到字符串变量,应将其拆分为较小的块,例如varchar(4000)
并将其加载到对象
,在下一步中,添加一个foreach循环容器
,将它们组合回字符串
变量
要将大文本拆分为小文本作为行,可以使用以下存储过程:
CREATE PROCEDURE SSIS_VarcharMax_Loader
@Input varchar(max) ,
@maxRowLength int = 50
AS
BEGIN
SET NOCOUNT ON
;WITH
tmp(inp,c,rn) as (
select @Input,SUBSTRING(@Input, 1,@maxRowLength),@maxRowLength
union all
select @Input,SUBSTRING(@Input,rn,@maxRowLength),rn + @maxRowLength
from tmp
where rn < len(@Input)
)
select c from tmp
OPTION (MAXRECURSION 500);
END;
@praveen:Hello,hole语句返回“john”、“doe”、“smith”,而不是(第1行)john(第2行)doe(第3行)smith。对于我的包,我需要在变量“deu sters”中加载确切的字符串“john”、“doe”和“smith”,因为它可以帮助我以后删除其他数据库中的内容。因此,如果运行HORE语句,则只返回“john”、“doe”、“smith”。非常感谢praveen。祝你今天愉快:)
CREATE PROCEDURE SSIS_VarcharMax_Loader
@Input varchar(max) ,
@maxRowLength int = 50
AS
BEGIN
SET NOCOUNT ON
;WITH
tmp(inp,c,rn) as (
select @Input,SUBSTRING(@Input, 1,@maxRowLength),@maxRowLength
union all
select @Input,SUBSTRING(@Input,rn,@maxRowLength),rn + @maxRowLength
from tmp
where rn < len(@Input)
)
select c from tmp
OPTION (MAXRECURSION 500);
END;
@strResult = (ISNULL(@[User::strResult])?"": @[User::strResult] )+ @[User::str]