Aparna Aparna - 2 months ago 10
SQL Question

How to remove the similar text from one column by comparing with other column in SQL Server

I have the following example

addressid 23915031
customerid 13154569
address1 FLAT NO 23 3Road Floor KRISH BUILDING ANUSHKTI
address2 GAR BARC COLONY Near SECTOR MARKET
address3 MANKHURoad MUMBAI
landmark ANUOHAKTING
zipcode 400094
addresstype RESIDENCE ADDRESS
cityname MUMBAI
statedesc MAHARASHTRA


In the above example I want to remove Mumbai from address3 field by comapring with cityname field. How to perform this in SQL server.
Please help!

Answer

Use this to address all the things:

UPDATE yourtable 
SET address3 = REPLACE(LTRIM(RTRIM(UPPER(address3))),LTRIM(RTRIM(UPPER(cityname))),'')
Comments