开发者

OPENQUERY update on linked server

开发者 https://www.devze.com 2023-01-10 07:33 出处:网络
I want to execute the following statement through from a link开发者_高级运维ed server (openquery):

I want to execute the following statement through from a link开发者_高级运维ed 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?


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消