General information
Forum:
Microsoft SQL Server
Title:
Using OPENQUERY passing a variable for the query.
I'm querying a linked server ( in this case, Visual Foxpro).
The query:
SELECT * FROM OPENQUERY(QTII_SYS_FOX,'SELECT LNAME FROM PATIENT WHERE PATIENTID = "1234567"')
gives me the results I want. However, I want to build the query dynamically at run time. When I have a variable called @SQLSTMNT that is equal to 'SELECT LNAME FROM PATIENT WHERE PATIENTID = "1234567"', I try to do the OpenQuery as
'SELECT * FROM OPENQUERY(QTII_SYS_FOX, @SQLSTMNT)'.
But I get a syntax error. Everything I've tried seems to indicate that SQL Server is simply not prepared to have anything except a literal there. Can anybody help me?
Thanks.
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only