Link to home
Start Free TrialLog in
Avatar of pgeisler
pgeisler

asked on

How do I pass a variable in a MSSQL linked server query?

Hello experts,

I would like to pass a variable in a linked server query. I am using MSSQL 2008 SQL server management studio.

I am querying a linked server running a Progress database

This query works

select count('order') as 'Orders Entered' from Openquery(V2, 'select order from oe_head where ord_date = ''12/28/2009'' and company_oe = ''cc'' and rec_type = ''o''')

I would like to pass a variable DATE for the ord_date but can't seem to get the syntax correct

Any ideas?

Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

you can only do that with dynamic sql, as OPENQUERY does (unfortunately) not allow a variable for the SQL ...
Avatar of pgeisler
pgeisler

ASKER

could you give an example?
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect example, it was the quote "hell of quotes" I was having trouble with.