Home Forums SQL Server 2005 Business Intelligence How to assign user variable a GUID value in Execute SQL Task using SSIS 2008 RE: How to assign user variable a GUID value in Execute SQL Task using SSIS 2008

  • mmohan.net (7/27/2011)


    Hello All,

    Here is the issue I’m facing.

    My task is to get guid’s from database field and run few updates based on the guid values.

    I had taken execute sql task which will execute a query to return bunch of guid’s. I had given Result Set as Full result set for Execute SQL task and declared a variable as user::sptkey. While declaring variable there is no data type of guid so I had taken it as string.

    My idea in assigning the result set to a user variable is to use foreach loop container and perform the updates based on the individual guid’s.

    When I try to execute the execute sql task individually here is the error message I got.

    [Execute SQL Task] Error: Executing the query "SELECT spt_key

    FROM TMPtable

    where spt_key = '9F8..." failed with the following error: "The type of the value being assigned to variable "User::strcst_key" differs from the current variable type. Variables may not change type during execution. Variable types are strict, except for variables of type Object.

    ". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

    Does anybody have idea what may be the issue.

    Thanks

    TMPTable.spt_key is a UNIQUEIDENTIFIER correct?

    What type of variable is User::strcst_key? It should be a DT_GUID. Integration Services Data Types

    If you want to store it in a string then you'll need to CAST it on the way out of SQL, like this:

    SELECT CAST(spt_key as VARCHAR(100)) as spt_key

    FROM TMPtable

    where spt_key = '9F8...'

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato