Pass text to OpenQuery function
Posted on 2010-04-05
Trying to query a linked server using a parameter. Can't seem to pass a string to the OpenQuery function
Select @TSQL = 'select product_id_i, prod_stl_days_i from product where product_id_i=259287'
Select * From OpenQuery([MUNIPRIME], 'select product_id_i, prod_stl_days_i from product where product_id_i=259287' ) A
Select * From OpenQuery([MUNIPRIME], @TSQL ) A
The first select will work. The second select using the same string will give the error
Msg 170, Level 15, State 1, Line 10
Line 10: Incorrect syntax near '@TSQL'.
Can someone tell me what's going on?