How do you pass parameter based queries to remote linked servers from SQL*Server?
It seems like such a basic functionality that it must be within SQL*Server to call remote non-SQL*Server data sources with a parameter.
OPENQUERY doesn't accept parameters within the query string portion, so the only option I can think of to pass parameters is to build up a query string with the relevant parameter values put in it. I cannot code this ahead of time as the values are not known until runtime.
For example, a userid from a website is passed to a stored procedure, the stored proc calls the remote server with OPENQUERY and some query...
select * from openquery(Linkedserver,'select * from
tableA
where id = 2345')
would be a query that SQL*Server would be able to run against a remote server. (in this case a non SQL*Server linked server)
If I need to supply the id value without hardcoding it in the stored proc I am unable to put in a parameter reference like ...
where id = @param
OpenQuery does not accept parameters. Yet OPENQUERY also doesn't seem to accept a string variable as the second part of the OPENQUERY call.
So in essence SQL*Server lets you call remote boxes if you always know at coding time what the remote condition values will be.
I can't imagine SQL*Server is that dumb. Or am I wrong? SQL*Server is just that dumb.
It seems like such a basic functionality that it must be within SQL*Server to call remote non-SQL*Server data sources with a parameter.
OPENQUERY doesn't accept parameters within the query string portion, so the only option I can think of to pass parameters is to build up a query string with the relevant parameter values put in it. I cannot code this ahead of time as the values are not known until runtime.
For example, a userid from a website is passed to a stored procedure, the stored proc calls the remote server with OPENQUERY and some query...
select * from openquery(Linkedserver,'select * from
tableA
where id = 2345')
would be a query that SQL*Server would be able to run against a remote server. (in this case a non SQL*Server linked server)
If I need to supply the id value without hardcoding it in the stored proc I am unable to put in a parameter reference like ...
where id = @param
OpenQuery does not accept parameters. Yet OPENQUERY also doesn't seem to accept a string variable as the second part of the OPENQUERY call.
So in essence SQL*Server lets you call remote boxes if you always know at coding time what the remote condition values will be.
I can't imagine SQL*Server is that dumb. Or am I wrong? SQL*Server is just that dumb.