链接服务器上的 OPENQUERY 更新

发布于 2024-09-12 20:11:26 字数 590 浏览 3 评论 0原文

我想通过链接服务器(openquery)执行以下语句:

UPDATE SAP_PLANT 
SET (OWNER, OWNER_COUNTRY) = (SELECT import.AFNAME, import.COUNTRY
                                FROM SAP_IMPORT_CUSTOMERS import, SAP_PLANT plant
                                WHERE plant.SAP_FL = import.SAP_NO
                                AND import.role ='OWNER')

我尝试将其形成以下语法,但没有成功:(

update openquery(‘my_linked_server, ‘select column_1, column_2 from table_schema.table_name where pk = pk_value’)
set column_1 = ‘my_value1′, column_2 = ‘my_value2′

我希望你这没有问题?

I want to execute the following statement through from a linked server (openquery):

UPDATE SAP_PLANT 
SET (OWNER, OWNER_COUNTRY) = (SELECT import.AFNAME, import.COUNTRY
                                FROM SAP_IMPORT_CUSTOMERS import, SAP_PLANT plant
                                WHERE plant.SAP_FL = import.SAP_NO
                                AND import.role ='OWNER')

I've tried to form it into the following syntax, without success :(

update openquery(‘my_linked_server, ‘select column_1, column_2 from table_schema.table_name where pk = pk_value’)
set column_1 = ‘my_value1′, column_2 = ‘my_value2′

I hope for you this is no problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦幻的味道 2024-09-19 20:11:26

我想这实际上并不是您想要打开的查询,而是您想要执行的 SQL 语句。因此,您应该使用execute,而不是openquery。请参阅此处的示例 G:http://msdn.microsoft.com/en-us/ library/ms188332.aspx

所以你的脚本应该看起来像

execute ('your sql command here') at my_linked_server

I guess this is not really a query you want to open, rather an SQL statement you want to execute. So instead of openquery, you shoud use execute. See example G here: http://msdn.microsoft.com/en-us/library/ms188332.aspx

So your script shoul look like

execute ('your sql command here') at my_linked_server
从来不烧饼 2024-09-19 20:11:26

您遇到语法错误吗? update openquery 中的服务器参数缺少尾部引号。将``my_linked_server更改为my_linked_server'`。

Are you getting syntax error? Your server parameter in the update openquery is missing a trailing quote. Change ```my_linked_servertomy_linked_server'`.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文