可以使用“INSERT INTO @VARIABLE EXEC() AT LINKED_SERVER”句法? (SQL Server 2005)
我正在尝试在链接服务器上执行查询,但我需要本地结果。
DECLARE @test TABLE
(
greeting CHAR(5)
)
INSERT INTO @test
EXEC('select ''hello'' as greeting')
SELECT * FROM @test
使用 EXEC()
和 INSERT INTO
但是,显然查询是在本地执行的。
DECLARE @test TABLE
(
greeting CHAR(5)
)
INSERT INTO @test
EXEC('select ''hello'' as greeting') AT LINKED_SERVER
SELECT * FROM @test
根本不起作用。
SELECTgreetingFROMOpenQuery(LINKED_SERVER,'SELECT''hello''ASgreeting')
完全实现了我想要的,但我需要使用动态字符串,而实现这一点的唯一方法是使我的整个查询成为一个巨大的字符串并将其放入 EXEC() 中,我不想这样做,因为它真的很难看......
感谢您的帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用以下内容:
假设您实际上不想只得到“hello”这个词...您可能想做一些事情,例如从表中实际选择一个值,那么上面的应该更有可能是你想要的。
You could use the following:
And assuming you don't want to actually just get the word "hello"... you probably want to do something like actually selecting a value from a table, then the above should be even more likely what you want.