Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using OPENQUERY passing a variable for the query.
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Using OPENQUERY passing a variable for the query.
Miscellaneous
Thread ID:
00457919
Message ID:
00457919
Views:
76
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
Map
View

Click here to load this message in the networking platform