SSIS Variables Do Not Like Varchar(MAX)

You may get an error when loading a string variable from a varchar(MAX) field via an Execute SQL Task. Here is the complete error I got when loading a variable named SQLStatement:

Error: 0xC001F009 at I_CTHNDL: The type of the value being assigned to variable “User::SQLStatement” differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.

A solution is to cast the return value of the select statement or, more drastically, modify the field definition in the database.

SELECT     CAST(SQLStatement AS varchar(8000)) AS SQLStatement
FROM         Z_SQLStatements
WHERE     (SQLStatementRef = 'ExtractHandlings')

8000 is the maximum value allowed in the cast. The SSIS variable happily accepts it.

2 Comments »

Comment by chaps
2008-08-08 16:21:52

Your post was really helpful.Thanks

 
Comment by smmcroberts
2008-10-10 12:32:39

Thanks for the tip, but my string really is larger than 8,000 characters, which is why I was using varchar(max). Is there any way to get SSIS to handle this? Is the SSIS Exec SQL Task return String type really limited to 8,000 characters?

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Trackback responses to this post