Link to home
Start Free TrialLog in
Avatar of FlyingFortress
FlyingFortressFlag for United Kingdom of Great Britain and Northern Ireland

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?.....

Avatar of Lee
Lee
Flag of United Kingdom of Great Britain and Northern Ireland image

update tbl_customer set address = REPLACE(Address, 'X', 'Y')
FROM         tbl_Customer
Avatar of FlyingFortress

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
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, 'X', 'Y')
FROM         tbl_Customer
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
ASKER CERTIFIED SOLUTION
Avatar of Lee
Lee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you!