OPENQUERY update on linked server

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?

Answers


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'`.


Need Your Help

The remote server returned an error: 227 Entering Passive Mode ()

c# asp.net

I am doing code which uploads file from one server to another, Following is my code:

superscript and subscript the same character in an expression

r plot expression

In a plot I would like a title which should have: