FlyingFortress
asked on
Using a replace command in SQL Server Express to remove certain strings in a table
Hi,
Using SQL Server Management Studio and I am trying to replace a certain string with another.
The Table - tbl_customer
The Column - Address
For the sake of testing looking for X and replacing it with Y - Here is my current effort.
update tbl_customer SELECT REPLACE(Address, 'X', 'Y')
FROM tbl_Customer
This seems to find the instance and displays the Y however, it does not update the table?.....
Using SQL Server Management Studio and I am trying to replace a certain string with another.
The Table - tbl_customer
The Column - Address
For the sake of testing looking for X and replacing it with Y - Here is my current effort.
update tbl_customer SELECT REPLACE(Address, 'X', 'Y')
FROM tbl_Customer
This seems to find the instance and displays the Y however, it does not update the table?.....
ASKER
Ok thanks for this how would I be able to set it to remove unwanted Quote marks. Again my effort
update tbl_customer set address = REPLACE(Address, '%"', 'Y')
FROM tbl_Customer
Thanks
update tbl_customer set address = REPLACE(Address, '%"', 'Y')
FROM tbl_Customer
Thanks
To remove single quotes:
update tbl_customer set address = REPLACE(Address, '''', '')
FROM tbl_Customer
To remove double quotes:
update tbl_customer set address = REPLACE(Address, '"', '')
FROM tbl_Customer
There is a subtle difference. When you put in a single quote into a SQL string you must "double up" so use two single quotes when you mean one. This escapes the character.
update tbl_customer set address = REPLACE(Address, '''', '')
FROM tbl_Customer
To remove double quotes:
update tbl_customer set address = REPLACE(Address, '"', '')
FROM tbl_Customer
There is a subtle difference. When you put in a single quote into a SQL string you must "double up" so use two single quotes when you mean one. This escapes the character.
update tbl_customer set Address = REPLACE(Address, 'X', 'Y')
FROM tbl_Customer
FROM tbl_Customer
ASKER
So will this work if the field contains "X" ?
The Quotes are also at the end of the text as well as the front I used the wild card % is that not needed in this case?
Cheers
FF
The Quotes are also at the end of the text as well as the front I used the wild card % is that not needed in this case?
Cheers
FF
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you!
FROM tbl_Customer