UPDATE OPENQUERY Help
I am trying to update an Oracle 11 table via a linked server in SQL, now the linked server and select statements all appear correct and I think I am very close to cracking this, but I am having issues with the update. The other OPENQUERY commands work correctly e.g.
SELECT * FROM OPENQUERY(LinkedServer, 'SELECT PL.place_id, PL.phy_svc_grp_b FROM OU_DBA.REQUEST RT INNER JOIN OU_DBA.PLACE PL ON RT.place_id = PL.place_id WHERE (RT.phy_svc_grp_b IS NULL) AND (PL.phy_svc_grp_b IS NOT NULL)')
This is performing as expected; this information is then placed into a temporary table and using a WHILE
I create an update openquery;
SET @TEMP_COUNT = (SELECT COUNT(*) FROM #MissingRegions)
WHILE @TEMP_INDEX < @TEMP_COUNT +1
BEGIN
-----Clear out the SQL String
SET @SQL_STRING = ''
-----Assign the Place ID.
SET @PLACE_ID = (SELECT PLACE_ID FROM #MissingRegions WHERE ID =@TEMP_INDEX)
-----Assign the Region.
SET @REGION = (SELECT GROUP_B FROM #MissingRegions WHERE ID =@TEMP_INDEX)
SET @SQL_STRING ='UPDATE OPENQUERY(LinkedServer, ''SELECT PHY_SVC_GRP_B FROM [OU_DBA].[REQUEST] WHERE PLACE_ID =''' + @PLACE_ID + ''')' + ' SET PHY_SVC_GRP_B = ''' + @REGION + ''''
PRINT @SQL_STRING
EXEC (@SQL_STRING)
----Increment the index value by 1
SET @TEMP_INDEX = @TEMP_INDEX +1
END
The output from the Print command returns the following;
UPDATE OPENQUERY(LinkedServer, 'SELECT PHY_SVC_GRP_B FROM [OU_DBA].[REQUEST] WHERE PLACE_ID ='ES5159') SET PHY_SVC_GRP_B = '1000'
But I keep getting the following error for each record i try to update; Msg 102, Level 15, State 1, Line 1 Incorrect syntax near 'ES5159'. Msg 105, Level 15, State 1, Line 1 Unclosed quotation mark after the character string ''.
If anyone could possibly suggest where I may be going wrong and provide a solution for this I would be extremely grateful.