SQL Server Linked Server with variable command
482162Jan 11 2006 — edited Jan 12 2006Hi All,
I'm working in SQL Server 2005 using a Linked Server against an Oracle 10 database. The linked server works correctly in that I can do:
Select * From OpenQuery(DssPrd, 'Select * From DwDba.Admit_Priority')
I'd like to be able to build the query string on the fly, eventually to add a variable to the string, and send the string variable. Something like this:
Declare @Sql Char(100)
Set @Sql = 'Select * From DwDba.Admit_Priority Where Admit_Priority = 5'
Select * From OpenQuery(DssPrd, @Sql)
Of course that doesn't work but is there any way to pass a variable in the OpenQuery() statement? (I've asked in a SQL Server forum with no responses yet.)
Thanks.