Reputation:
I have to replace special characters in SQL.
My problem is with '
, because it is used for start and end of string in SQL.
I tried:
ID = REPLACE(ID, ''', '')
ID = REPLACE(ID, "'", "")
But both not worked. What should I do?
Upvotes: 1
Views: 87
Reputation: 1555
Either Use the char function and ascii code:
ID = REPLACE(ID, char(39), '')
or double down on the single quotes:
ID = REPLACE(ID, '''', '')
Upvotes: 1
Reputation: 13237
ID = REPLACE(ID, '''', '')
will work.
Demo with sample data:
DECLARE @ID AS VARCHAR(10) = 'Test''data';
SELECT @ID, REPLACE(@ID, '''', '')
it will remove the single quote from the given string.
Upvotes: 2