Knowledgebase: Tutorials
[QODBC-Desktop] Troubleshooting - How to use parameter in OPENQUERY
Posted by Jack - QODBC Support on 04 May 2015 01:58 PM

Problem Description:

How to use parameter in OPENQUERY


OPENQUERY does not accept variables for its arguments. You need to Pass Basic Values as below example:

Select Query:

DECLARE @TSQL varchar(8000), @ID varchar(25)

SELECT @ID = '19650'

SELECT @TSQL = 'SELECT * FROM OPENQUERY(QRemote ,''SELECT * FROM ReceivePayment WHERE ReceivePayment.RefNumber = ''''' + @ID + ''''''')'


Update Query:

DECLARE @TSQL varchar(8000), @ID varchar(25), @CName varchar(25)

SELECT @ID = '80000146-1513345553'

SELECT @CName = 'New Company'

SELECT @TSQL = 'Update OPENQUERY(QRemote ,''SELECT * FROM Customer WHERE Customer.ListID = ''''' + @ID + ''''''')' + 'SET CompanyName = ''' + @CName + ''''


Please refer below link:
How to pass a variable to a linked server query
Including parameters in OPENQUERY

(2 vote(s))
Not helpful

Comments (0)
Post a new comment
Full Name:
CAPTCHA Verification 
Please complete the captcha below (we use this to prevent automated submissions).