Solved

Exact string match and replace in SQL??

Posted on 2008-10-01
3
2,079 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
ID: 22619061
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
ID: 22619295
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
ID: 22619591
Thanks.
It came to me after I saw this....hhh.!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Filtering characters in an SQL field 2 19
how to double quote a string for an inline sql statement. 8 88
table joins in qry 17 82
sql server query 12 32
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

679 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