How to use replace in openquery SQL?
-
14-04-2021 - |
Domanda
I need to remove Special characters from columns which has them from linked server using OpenQuery.
Here is the example, but it's not working
DECLARE @Query VARCHAR(MAX)
SET @Query =
'
UPDATE OPENQUERY
(
LINKEDSERVER,
''SELECT * FROM TABLE WHERE NAME Like ''''' + '%###%' + '''''''
)
SET NAME = REPLACE(NAME, ''###'', '''')
'
EXEC (@Query)
Soluzione
Your question does not seem to match the code you're trying to use. Are the columns you're trying to clense of values in a table on a linked sever?
Then maybe this is what your looking for:
UPDATE OPENQUERY (LINKEDSERVER, 'SELECT name FROM Table WHERE name like ''%###%'' ')
SET name = REPLACE(NAME, '###', '');
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow