Friday, March 9, 2012

Pass variables to an OPENQUERY

Hi all,

Does anyone know if it is possible to pass variabes to an openquery statement?

I am trying to do something like this:

OPENQUERY(LinkServer, 'SELECT column1, column2 FROM table WHERE column3 ='' + @.@.variable1 +'' AND column4 = '' +@.@.variable2 +'')

Many thanks in advance,

-Vicky

Hi vicky,

If you are using SS 2005, then take a look to EXEC in BOL. You can use the "at linked_server_name" feature and use also parameters. If you are using 2000, then you will have to deal with dynamic sql.

The Curse and Blessings of Dynamic SQL

http://www.sommarskog.se/dynamic_sql.html#OPENQUERY

AMB

|||Thanks a lot!. This was helpful.

No comments:

Post a Comment