'Need replace text with single quotes in SQL
I need to make a script that make a replacement of all the registers of a column that contains: '@xxxx', removing the single quotes. (xxxx could be empty or any string. The @, is neccesary, the simple quotes too).
I'm implementing something like this, but it doesn't work for me, because the 'REPLACE' function accepts Strings as parameters, instead of accepting other functions.
Thanks
I tried
UPDATE MY_TABLE SET MY_COLUMN = REPLACE('MY_COLUMN',
SELECT "MY_COLUMN" FROM MY_TABLE WHERE "MY_COLUMN" like '%''@%',
SELECT TRIM( '%''%' FROM MY_TABLE WHERE "MY_COLUMN" like '%''@%'))
Solution 1:[1]
Its unclear what dbms you are using, but here is what I would so in SQLServer, you can modify for you dbms if not this.
They key point here is you are doing this the wrong way round, you use the Replace function on each row, not pass the record set into the replace.
UPDATE mt
SET myColumn = REPLACE(myColumn, '''','')
FROM myTable mt
WHERE myColumn LIKE '%''@%'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | OCDan |