Assign value to GlobalVariable in ExecuteSqlTask

  • How can I assign value to GlobalVariable

    in ExecuteSqlTask in DTS using parametrs button?

    I tried this:

    declare @var char(2)

    set @var='kk'

    set ?=@var

    when I press Parametrs button to define parameter i receive an error.

    Thanks in advance

  • As far as I am aware you do not need to declare the variable in the SQL. Just type in your query i.e. select field1 from table1 and then click on the parameters button. On Output Parameters select row value and next to the field that holds the value you require select the global variable.

    Hope this helps

  • I would put my code in a stored procedure with the variable defined as an output variable. Then you can assign the value of the output variable to the global variable through the parameters button. Something like:

    CREATE PROCEDURE mystoredproc

    @var char(2) OUTPUT

    AS

    SELECT @var = 'kk'

    RETURN(0)

    GO

    In your ExecuteSQLTask you can do something like this:

    EXEC mystoredproc ?

    GO

    On the parameters tab of the ExecuteSQLTask, set the value of your global variable to the output variable.

    Hope this helps get you going in the right direction...all of this is in Books OnLine in SQL Server - search under 'global variables' in the DTS category.

    Michael Weiss


    Michael Weiss

  • thanks for help

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply