Werner
Werner

Reputation: 35

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?

Upvotes: 1

Views: 7220

Answers (2)

Las Ten
Las Ten

Reputation: 1175

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

Upvotes: 5

bobs
bobs

Reputation: 22184

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

Upvotes: 1

Related Questions