How to use a global variable in T-SQL?

  • I wish to insert the value of a global variable in an ExecuteSQL task. In my simplicity I think of doing it like this:

    INSERT INTO Table1(message)

    SELECT ?

    I have defined a glovar in the package, assigned a messeagestring. The package end with an errormessage: Syntax error or Acces violation.

    Obviously it's a syntax-error. When I use a real value for the ? the statement is executed without problem. I cannot find info on this specific issue. I can use an activex script, but there are reasons to do this within an ExecuteSQL task as well.

    How do I do something like this with T-SQL?

    Greetz,
    Hans Brouwer

  • You can use the following syntax to insert the value in the task.

    insert into Table1(message) values (?)

  • Tnx, why did I not think of that;-)

    I forgot to ask: can I ASSIGN a value to a glovar in T-SQL? I can do it in ActiveX, but it would be handy to be able to do this in T-SQL as well.

    Tnx again

    Greetz,
    Hans Brouwer

  • The best way to do this is to use the dynamic property task. You can set the variable from a query or various other (e.g. ini file)

  • I know the Dynamic Props Task.

    Basically I am trying to create a loggingmechanism in a DTS-package. There are several tasks: ActiveX, ExecuteSQL and Datapump. When a tasks fails, a global variable would be set with taskname, and then I would like to point to 1 task, either an ExecuteSQL or an ActiveX, which inserts this name(+ some more info) in a loggingtable.

    From ActiveX-tasks I can do this without problem. From an ExecuteSQL task I would also be able to set a glovar and then go with the Failed Workflow to this 1 errorhandling/ logging-task.

    But I am beginning to wonder if it is possible to set a glovar in T-SQL.

    Greetz,
    Hans Brouwer

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

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