sql statement in "Execute SQL task"

  • I am new in SSIS,

    and I am building some ETL just to make some exercises.

    In the "Execute SQL task" page general and property: SQL Statement, I try to insert this SQL Statement,

    "INSERT INTO table SELECT '" + @[User::myVariable] + "'"

    or

    "INSERT INTO table SELECT '" + @myVariable + "'"

    but parsing, I get an error:

    incorrect syntiax near '+'.

    Do you know any suggestions?

    Thank

     

  • This was removed by the editor as SPAM

  • Where are you trying to set the SQL statement with the variable? In Expressions I don't see SQL Statement as an available property that you can set?

    Tim

    Denver, CO

  • The best way to accomplish your task is to use Dynamic SQL.  You'll have to create a variable to store your SQL Statement and your variable in and then execute that variable because SQL doesn't like adding a variable into the actual execution statement.

    Here's an example of what I'm talking about.  The below script is an exerpt from a T-SQL job that copies a backup from one network share to another after deleting the previous day's backup file.  @OldFileName has already be set using a temp table that reads in the directory from that share.

    Declare @removefile As Varchar(200)

    set @removefile = 'Del G:\SQL_BAK\apacs\CopyForQCDev\' + @OldFileName;

    Exec Master..Xp_cmdshell @removefile;

     

    Does that make sense?  If not, let me know.

     

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • Hi,

    thank for your reply, I solved the problem:

    before I had a mistake inserting the INSERT... into SQL statement, then I moved to the expression field and now it works.

     

    Thank 

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

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