简体   繁体   中英

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.

I built a piece of SQL code to do that which works great. 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. the most recent attempt truncated 4184 characters to 4058.

I know that nvarchar is limited to 4000 characters in SSIS. One suggestion was to use nvarchar(max) source data type and Object variable type. That fails with this error:

"An error occurred while extracting the result into a variable of type (DBTYPE_WSTR)".

Another was to use ntext in the source query. That fails with this error:

"The text, ntext, and image data types are invalid for local variables."

Am I missing something? What's the correct way to put a long string into an Execute SQL result set variable?

Here's the original code to get the SQL command, the code that works but truncates. The puts an escaped single quote around the ID. (These particular IDs are varchar because they can contain letters.)

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.

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.
  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.

Described approach allowed to transfer long (more that 8K symbols) strings from SQL into SSIS String variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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