egreenberg
Programmer
I am writing a stored proc. that will copy data from tables in a remote location, to nearly identical tables in my local db. I need to pass a variable that is declared and set on my local db, into the query that selects data from the remote db. I am doing these queries throught OPENROWSET.
example:
DECLARE @bank_id int
SET @bank_id = 1
SELECT a.*
FROM OPENROWSET('SQLOLEDB','xx.xx.xxx.xxx';'username';'password','SELECT * FROM DBName.dbo.tblBanks WHERE bank_id ='@bank_id)
AS a
the problem is that the parser doesn't recognize the @bank_id when it is used in the OPENROWSET(), presumably because it is declared and set on my local db, and I am trying to use it in a remote query. I've tried several variations of the above example.
Question: how can I get the value of the locally declared variable into the remote query? I already tried to put the whole SELECT statement into a string variable, concatenate with @bank_id, and then use that string variable in the remote query but to no avail.
If anyone can help, much appreciation and many good thoughts will be sent your way.
Thanks!
example:
DECLARE @bank_id int
SET @bank_id = 1
SELECT a.*
FROM OPENROWSET('SQLOLEDB','xx.xx.xxx.xxx';'username';'password','SELECT * FROM DBName.dbo.tblBanks WHERE bank_id ='@bank_id)
AS a
the problem is that the parser doesn't recognize the @bank_id when it is used in the OPENROWSET(), presumably because it is declared and set on my local db, and I am trying to use it in a remote query. I've tried several variations of the above example.
Question: how can I get the value of the locally declared variable into the remote query? I already tried to put the whole SELECT statement into a string variable, concatenate with @bank_id, and then use that string variable in the remote query but to no avail.
If anyone can help, much appreciation and many good thoughts will be sent your way.
Thanks!