Solved

Exact string match and replace in SQL??

Posted on 2008-10-01
3
1,976 Views
Last Modified: 2008-10-01
Hi,

This column called Destinations has country names like Cananda,France or Iran/Syria.
I am trying to replace those with the trigraphs.
How do I match exact string??

I changed Iran to IRQ then I had a few IR. so when I replace IR with IRQ.
Previous IRQ became, IRQQ.

Is it possible to match exactly string not partial??

I used update table set location=replace(location, 'sss','dffdf')

Thannks

0
Comment
Question by:dkim18
3 Comments
 
LVL 22

Accepted Solution

by:
dportas earned 350 total points
Comment Utility
Use the WHERE clause for an exact match on the string:

UPDATE tbl SET location = 'sss'
WHERE location = 'dffdf';
0
 
LVL 39

Assisted Solution

by:BrandonGalderisi
BrandonGalderisi earned 150 total points
Comment Utility
This won't be the most efficient because it will update Location = location for all records that you don't specify.... but it give you the idea on how to build it out.
update YourTable

set Location = case location when 'IR' then 'IRQ'

                                when 'IRAN/SYRIA' then 'IRN'

                                when 'Canada' then 'CAN'

                                else location

end

Open in new window

0
 

Author Comment

by:dkim18
Comment Utility
Thanks.
It came to me after I saw this....hhh.!!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now