简体   繁体   English

SSIS 2012截断执行SQL任务的结果集

[英]SSIS 2012 truncates result set of Execute SQL task

Searched high and low on this and found many suggestions, but nothing that works for me. 对此进行了高低搜寻,发现了很多建议,但对我没有任何帮助。 We have a table with a field that stores SQL queries in a text type column, and the query is subsequently called by other objects, thus a need to escape certain characters. 我们有一个带有字段的表,该字段在文本类型列中存储SQL查询,该查询随后被其他对象调用,因此需要转义某些字符。

I built a piece of SQL code to do that which works great. 我构建了一段SQL代码来完成这一工作。 The problem is, when put in an Execute SQL task and assigning the results to a String variable, the text is truncated at seemingly random, ex. 问题是,当放入Execute SQL任务并将结果分配给String变量时,文本会在看似随机的地方被截断,例如。 the most recent attempt truncated 4184 characters to 4058. 最近的尝试将4184个字符截断为4058个字符。

I know that nvarchar is limited to 4000 characters in SSIS. 我知道nvarchar在SSIS中限制为4000个字符。 One suggestion was to use nvarchar(max) source data type and Object variable type. 一种建议是使用nvarchar(max)源数据类型和Object变量类型。 That fails with this error: 失败并显示此错误:

"An error occurred while extracting the result into a variable of type (DBTYPE_WSTR)". “将结果提取到类型为(DBTYPE_WSTR)的变量中时发生错误”。

Another was to use ntext in the source query. 另一个是在源查询中使用ntext。 That fails with this error: 失败并显示此错误:

"The text, ntext, and image data types are invalid for local variables." “ text,ntext和image数据类型对于局部变量无效。”

Am I missing something? 我想念什么吗? What's the correct way to put a long string into an Execute SQL result set variable? 将长字符串放入Execute SQL结果集变量的正确方法是什么?

Here's the original code to get the SQL command, the code that works but truncates. 这是获取SQL命令的原始代码,该代码有效但会被截断。 The puts an escaped single quote around the ID. Put在ID周围加上一个转义的单引号。 (These particular IDs are varchar because they can contain letters.) (这些特定的ID为varchar,因为它们可以包含字母。)

DECLARE @IDList VARCHAR(8000)
SELECT @IDList = COALESCE(@IDList + ', ', '') + '''''' + PersonID + '''''' 
FROM tmpGroup

select '''SELECT SystemID
FROM People
WHERE PersonID IN (' + @IDList + ')''' AS GroupSQL

Note it uses VARCHAR(8000) because that's the only source data type that seems to work. 请注意,它使用VARCHAR(8000),因为这是唯一起作用的源数据类型。

I fixed similar problem with the following: 我修复了以下类似问题:

  1. In Execute SQL Task - set ResultSet = Full result set and assign Object variable (VObj) as a result set. 在“执行SQL任务”中-设置ResultSet =完整结果集,并将对象变量(VObj)分配为结果集。
  2. After this task - create Foreach ADO enumerator and process Vobj as the source variable ( see good walk through article ), assigning the first variable to some String variable. 完成此任务后-创建Foreach ADO枚举器并将Vobj作为源变量处理( 请参阅完整的入门文章 ),将第一个变量分配给一些String变量。

Described approach allowed to transfer long (more that 8K symbols) strings from SQL into SSIS String variable. 描述的方法允许将长(超过8K个符号)字符串从SQL传输到SSIS String变量中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM