I am trying to execute a query on a linked server, but I need the results locally.
DECLARE @test TABLE
(
greeting CHAR(5)
)
INSERT INTO @test
EXEC('select ''hello'' as greeting')
SELECT * FROM @test
Uses an EXEC()
and INSERT INTO
but, obviously the query is executing locally.
DECLARE @test TABLE
(
greeting CHAR(5)
)
INSERT INTO @test
EXEC('select ''hello'' as greeting') AT LINKED_SERVER
SELECT * FROM @test
Does not work at all.
SELECT greeting FROM OpenQuery(LINKED_SERVER,'SELECT''hello'' AS greeting')
Accomplishes exactly what I want, but I need to be using a dynamic string, and the only way to make that work is to make my entire query a huge string and put it into an EXEC(), which I don't want to do since it is really ugly....
Thanks for any help!