Insert based on condition

  • It's late on Friday.....drawing a blank....

    How can I get a 4part name into a variable to use for an insert statement?

    If x

    Insert into db.dbo.table (Local sql server)

    select a, b, c from table, join, table, blah

    If y (Remote sql server)

    insert into server.db.dbo.table

    select a, b, c from table, join, table, blah

    Is there a way to put the server, db, dbo, table into a variable & use the variable in the insert statement?

    thx

  • You wold need to use dynamic SQL for such a requirement.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • are you inserting into multiple linked servers or do you have just one ?

    Jayanth Kurup[/url]

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

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