Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Replacing Multiple rows with searched multiple values

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-17-03, 07:16
selander selander is offline
Registered User
 
Join Date: Apr 2003
Posts: 4
Question Replacing Multiple rows with searched multiple values

I have two tables..

Table1.Field1 Values ("North Highway", "Green Street", "Blue Road", "Pink Lane")

Table1.Field1 Values (" Road", " Lane", " Street", " Highway")
Table2.Field2 Values (" Rd.", " Ln.", " St.", " Hwy.")

I would like to create a function or a sp_ that searches Table1.Field1 for the values in Table2.Field1 AND replaces it with Table2.Field2

Possible?
How?

It would of course be possible with a
replace(replace(replace(Table1.Field1," Road"," Rd.")," Lane"," Ln.")," Street"," St.")

But friends, I dont think I need to mention that this is purely an example..
Table2 contains about 260 records.

thnx.

Marcus
Reply With Quote
  #2 (permalink)  
Old 05-03-03, 05:06
ClaireHsu ClaireHsu is offline
A Human
 
Join Date: May 2003
Location: Parsippany NJ
Posts: 36
Wink

you dont need to create a function.BTW,you provided incorrect info.
Table1.Field1 Values (" Road", " Lane", " Street", " Highway")
Table2.Field2 Values (" Rd.", " Ln.", " St.", " Hwy.")

should be
Table2.Field1 Values (" Road", " Lane", " Street", " Highway")
Table2.Field2 Values (" Rd.", " Ln.", " St.", " Hwy.")

Here is the query

update table1 set field1 =
substring(field1,1,charindex(' ',field1)-1)+
(case when right(field1,len(field1)-charindex(' ',field1))= 'Highway' then ' Hwy.'
when right(field1,len(field1)-charindex(' ',field1))= 'Street' then ' St.'
when right(field1,len(field1)-charindex(' ',field1))= 'Lane' then ' Ln.'
when right(field1,len(field1)-charindex(' ',field1))= 'Road' then ' Rd.' end) from table1
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On