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

  • patelmia (7/28/2011)


    Hi opc.three,

    Thanks for your reply. Do you have any sample peice of code which shows how to use object inorder to acheive this task.

    If you're going to be using the GUID to submit back to the database as part of another SQL query then I think you'll want to use the string approach and CAST your UNIQUEIDENTIFIER column to a CHAR(36) on the way out. Forget that I used a VARCHAR(100) before, that was for expediency, I did not check to see which data type would be best for the job. CHAR(36) is the proper datatype.

    my taks is I will get 10 guid's from select query need to loop through each guid and do some updates on other table with guid value.

    I would recommend this workflow in your SSIS pkg:

    1. Use an Execute SQL Task where the Resultset is set to "Full result set". The query should retrieve your GUIDs (cast as strings) and store that in a variable of type Object.

    2. Use a ForEach Loop Container to iterate over the ADO Recordset in your Object variable.

    3. Inside your ForEach Loop Container use however many Execute SQL Tasks you need to make further changes to the database. On the Execute SQL Task you can dynamically set the value of teh the SqlStatementSource Property using an Expression. The Expression will be your query which you can build using the GUID variable supplied by your ForEach Loop Container.

    It sounds like a lot, but it's not too difficult. Here are some visual tutorials on working with Expressions in SSIS to help you get started.

    Intro on Expressions: Expression Language Basics

    This is related to Step 2 above. Using the For Each ADO Enumerator

    This one is not directly related to your problem, but it does show how to set a property using an Expression. Adding a Time Stamp to a File Name in SSIS

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