473,750 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using UPDATE to sequentially abbreviate address information

Greetings,

I'm trying to update an address field with "standard" abbreviations so
that I can do a comparison of various accounts to one another on the
address. I can update a set of records for "Road" to "Rd", but when I
tried to stack the update clauses, I seem to get random updates within
the file. All the updates are correct, but they're incomplete. Not
sure how this needs to be done, I added a TOP statement but that
didn't work. Is there way to simply string these together in a single
query?

The basic idea is to create the new address, "address_line_1 _fix",
while leaving the original address, "address_line_1 ", intact.

UPDATE TOP (100) PERCENT dbo.All_Client_ Companies_For_F ix
SET address_line_1_ fix = REPLACE(address _line_1,'Road', 'Rd')
WHERE address_line_1 like '%Road%'
GO
UPDATE TOP (100) PERCENT dbo.All_Client_ Companies_For_F ix
SET address_line_1_ fix = REPLACE(address _line_1,'Avenue ','Ave')
WHERE address_line_1 like '%Avenue%'
GO
UPDATE TOP (100) PERCENT dbo.All_Client_ Companies_For_F ix
SET address_line_1_ fix = REPLACE(address _line_1,'Street ','St')
WHERE address_line_1 like '%Street%'
GO
UPDATE TOP (100) PERCENT dbo.All_Client_ Companies_For_F ix
SET address_line_1_ fix = REPLACE(address _line_1,'Boulev ard','Blvd')
WHERE address_line_1 like '%Boulevard%'
GO
Jul 2 '08 #1
10 3571
First of all get rid of the TOP (100) PERCENT nonsense. While it
should have no effect, it serves no purpose and just confuses things.

Second, if you are saying that not all rows you expect to be updated
are updated, turn your UPDATE commands into queries and see what is
returned. If the SELECT returns rows using a given WHERE clause, then
an UPDATE with the same WHERE clause should update the same rows. Also
double check the spelling of the literals; a different spelling of
'Boulevard' in the WHERE clause and SET clause would not work right.

If you want to do this in a single query you need to nest the REPLACE
functions, and OR the tests.

UPDATE dbo.All_Client_ Companies_For_F ix
SET address_line_1_ fix =
REPLACE(
REPLACE(
REPLACE(
REPLACE(address _line_1,
'Boulevard','Bl vd'),
'Street','St'),
'Avenue','Ave') ,
'Road','Rd')
WHERE (address_line_1 like '%Road%'
OR address_line_1 like '%Avenue%'
OR address_line_1 like '%Street%'
OR address_line_1 like '%Boulevard%')

Roy Harvey
Beacon Falls, CT

On Wed, 2 Jul 2008 12:26:57 -0700 (PDT), Chris H
<ch********@bro adreachpartners inc.comwrote:
>Greetings,

I'm trying to update an address field with "standard" abbreviations so
that I can do a comparison of various accounts to one another on the
address. I can update a set of records for "Road" to "Rd", but when I
tried to stack the update clauses, I seem to get random updates within
the file. All the updates are correct, but they're incomplete. Not
sure how this needs to be done, I added a TOP statement but that
didn't work. Is there way to simply string these together in a single
query?

The basic idea is to create the new address, "address_line_1 _fix",
while leaving the original address, "address_line_1 ", intact.

UPDATE TOP (100) PERCENT dbo.All_Client_ Companies_For_F ix
SET address_line_1_ fix = REPLACE(address _line_1,'Road', 'Rd')
WHERE address_line_1 like '%Road%'
GO
UPDATE TOP (100) PERCENT dbo.All_Client_ Companies_For_F ix
SET address_line_1_ fix = REPLACE(address _line_1,'Avenue ','Ave')
WHERE address_line_1 like '%Avenue%'
GO
UPDATE TOP (100) PERCENT dbo.All_Client_ Companies_For_F ix
SET address_line_1_ fix = REPLACE(address _line_1,'Street ','St')
WHERE address_line_1 like '%Street%'
GO
UPDATE TOP (100) PERCENT dbo.All_Client_ Companies_For_F ix
SET address_line_1_ fix = REPLACE(address _line_1,'Boulev ard','Blvd')
WHERE address_line_1 like '%Boulevard%'
GO
Jul 2 '08 #2
There are address data scrubbing products from Melissa Data and Group
One which will do this for you and a lot more. Do not re-invent the
wheel.
Jul 2 '08 #3
Please remove the silly TOP 100 PERCENT.

A potential problem with your replaces is that you are not using any
delimiter. If you address line reads "Broadway", then the "Road"-part
will be replaced with "Rd" resulting in "BRdway".

So you will need to figure out how to properly replace any individual
term, for example by prefixing and/or postfixing a space to both the
search term and the replacement term.

Once that is correct, you can simply nest several replacements into one
UPDATE statement. Something like this:

UPDATE dbo.All_Client_ Companies_For_F ix
SET address_line_1_ fix = REPLACE(REPLACE (
address_line_1, 'Road', 'Rd')
, 'Street', 'St')
WHERE address_line_1 LIKE '%Road%'
OR address_line_1 LIKE '%Street%'

--
Gert-Jan
SQL Server MVP
Chris H wrote:
>
Greetings,

I'm trying to update an address field with "standard" abbreviations so
that I can do a comparison of various accounts to one another on the
address. I can update a set of records for "Road" to "Rd", but when I
tried to stack the update clauses, I seem to get random updates within
the file. All the updates are correct, but they're incomplete. Not
sure how this needs to be done, I added a TOP statement but that
didn't work. Is there way to simply string these together in a single
query?

The basic idea is to create the new address, "address_line_1 _fix",
while leaving the original address, "address_line_1 ", intact.

UPDATE TOP (100) PERCENT dbo.All_Client_ Companies_For_F ix
SET address_line_1_ fix = REPLACE(address _line_1,'Road', 'Rd')
WHERE address_line_1 like '%Road%'
GO
UPDATE TOP (100) PERCENT dbo.All_Client_ Companies_For_F ix
SET address_line_1_ fix = REPLACE(address _line_1,'Avenue ','Ave')
WHERE address_line_1 like '%Avenue%'
GO
UPDATE TOP (100) PERCENT dbo.All_Client_ Companies_For_F ix
SET address_line_1_ fix = REPLACE(address _line_1,'Street ','St')
WHERE address_line_1 like '%Street%'
GO
UPDATE TOP (100) PERCENT dbo.All_Client_ Companies_For_F ix
SET address_line_1_ fix = REPLACE(address _line_1,'Boulev ard','Blvd')
WHERE address_line_1 like '%Boulevard%'
GO
Jul 2 '08 #4
On Jul 2, 4:12*pm, "Roy Harvey (SQL Server MVP)" <roy_har...@sne t.net>
wrote:
First of all get rid of the TOP (100) PERCENT nonsense. *While it
should have no effect, it serves no purpose and just confuses things.

Second, if you are saying that not all rows you expect to be updated
are updated, turn your UPDATE commands into queries and see what is
returned. *If the SELECT returns rows using a given WHERE clause, then
an UPDATE with the same WHERE clause should update the same rows. Also
double check the spelling of the literals; a different spelling of
'Boulevard' in the WHERE clause and SET clause would not work right.

If you want to do this in a single query you need to nest the REPLACE
functions, and OR the tests.

UPDATE dbo.All_Client_ Companies_For_F ix
SET address_line_1_ fix =
* * * *REPLACE(
* * * *REPLACE(
* * * *REPLACE(
* * * *REPLACE(addres s_line_1,
* * * * * * * *'Boulevard','B lvd'),
* * * * * * * *'Street','St') ,
* * * * * * * *'Avenue','Ave' ),
* * * * * * * *'Road','Rd')
WHERE (address_line_1 like '%Road%'
OR * * address_line_1 like '%Avenue%'
OR * * address_line_1 like '%Street%'
OR * * address_line_1 like '%Boulevard%')

Roy Harvey
Beacon Falls, CT
I started without the TOP clause but since didn't update, I tried it
as an option (no problem removing). When I execute the query, I get
reporting to the effect that there were updates applied. See below.
Which leads me to the solution that I just figured out while typing
this.... I'm replacing the subsequent updates from the original
Address (and undoing the previous statements).

(3597 row(s) affected)

(2970 row(s) affected)
.....
(95 row(s) affected)

(142 row(s) affected)

The fix was to move address_line_1_ fix (not - address_address _line_1)
into the replace clause:

UPDATE dbo.All_Client_ Companies_For_F ix
SET address_line_1_ fix = REPLACE(address _line_1_fix,'St reet','St')
WHERE address_line_1_ fix like '%Street%'
UPDATE dbo.All_Client_ Companies_For_F ix
SET address_line_1_ fix =
REPLACE(address _line_1_fix,'Bo ulevard','Blvd' )
WHERE address_line_1_ fix like '%Boulevard%'
GO
Jul 2 '08 #5
On Wed, 2 Jul 2008 13:21:46 -0700 (PDT), --CELKO--
<jc*******@eart hlink.netwrote:
>There are address data scrubbing products from Melissa Data and Group
One which will do this for you and a lot more. Do not re-invent the
wheel.
They look really useful. Please send me the money to buy them.

Iain
Jul 4 '08 #6
Iain Sharp wrote:
On Wed, 2 Jul 2008 13:21:46 -0700 (PDT), --CELKO--
<jc*******@eart hlink.netwrote:
>There are address data scrubbing products from Melissa Data and Group
One which will do this for you and a lot more. Do not re-invent the
wheel.

They look really useful. Please send me the money to buy them.
And how much money (or equivalent labor) were you going to spend on
rolling your own? I've never needed to do significant amounts of
address scrubbing, but if I did, I would certainly consider these
products likely to be a worthwhile investment.
Jul 4 '08 #7
On Fri, 04 Jul 2008 13:01:27 -0700, Ed Murphy <em*******@soca l.rr.com>
wrote:
>Iain Sharp wrote:
>On Wed, 2 Jul 2008 13:21:46 -0700 (PDT), --CELKO--
<jc*******@ear thlink.netwrote :
>>There are address data scrubbing products from Melissa Data and Group
One which will do this for you and a lot more. Do not re-invent the
wheel.

They look really useful. Please send me the money to buy them.

And how much money (or equivalent labor) were you going to spend on
rolling your own? I've never needed to do significant amounts of
address scrubbing, but if I did, I would certainly consider these
products likely to be a worthwhile investment.

Hmmm, about 15 minutes, at UKP11/hour = UKP2.75.

Iain
Jul 7 '08 #8
What is a UKP?

If you have only spent 15 mins scrubbing address data, you have been
exceptionally lucky to have only worked with unbelievably high quality
data.

J
Jul 7 '08 #9
(jh******@googl email.com) writes:
What is a UKP?
A currency that according to ISO 4217 is known as GBP. Or £ for short.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jul 7 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3270
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old scripts working on a new server with the most recent version of PHP. I've pretty much taken care of all the various errors that were popping up. Most only pointed out out non-fatal undefined or assumed variables. I've been able to cure most of...
1
5090
by: Bennett Haselton | last post by:
Suppose I add a new row to a table in a dataset, and then I use an OleDbDataAdapter to add that new row to a SQL Server database using OleDbDataAdapter.Update(), as in the following code: dsLocalDataSet.user_postRow newRow = dsLocalDataSet1.user_post.Newuser_postRow(); newRow.post_text = this.lblHiddenMessageStorage.Text; newRow.post_datetime = System.DateTime.Now; dsLocalDataSet1.user_post.Adduser_postRow(newRow);...
1
2023
by: mursyidatun ismail | last post by:
Dear all, database use: Ms Access. platform: .Net i'm trying to update a record/records in a table called t_doctors by clicking da edit link provided in the database. when i ran through da browsers and click update it gave me this error: Specified argument was out of the range of valid values. Parameter name:
6
17205
by: ransoma22 | last post by:
I developing an application that receive SMS from a connected GSM handphone, e.g Siemens M55, Nokia 6230,etc through the data cable. The application(VB.NET) will receive the SMS automatically, process and output to the screen in my application when a message arrived. But the problem is how do I read the SMS message immediately when it arrived without my handphone BeEPINg for new message ? I read up the AT commands, but when getting down...
2
4465
by: BOS | last post by:
Hi there, I just create a form that contains name, Address, City, State, Zip, Question Checked box, and dropdown list selection for the user to fill-out the answer in the texbox, checkbox or choose the selection the option... For example here is the Form properties I setup: Text="Name" Text ID="LabelName" TextBox="TextBoxName" Text="Address" Text ID="LabelAddress" TextBox="TextBoxAddress" Text="City" Text ID="LabelCity" ...
4
2843
by: slavisa | last post by:
Im having trouble with updating my 1 table with the information from another! I have a table with 6 fields. Code(pk), Name, Title, Address, State, city, zip the table is called Info. Now i have a excel file which i imported it in the access db as a table called newinfo
10
2028
by: Sudhakar | last post by:
i am using $ip= $_SERVER to retrieve the ip address of the client for example if the value returned from $ip is 50.160.190.150 i would like to find out which country the request has come from. i believe by using the third set of numbers (in this case=190) from an ip address we can find out the country name. i can declare a variable with a list of country names and the range of values, what i need help is to extract the 3rd set of...
7
3109
by: Sunny | last post by:
Hi, Is there a way in Javascript to abbreviate currency. Like if it is $1000 then it convert it into 1K.
1
4610
by: javediq143 | last post by:
Hi All, This is my first post in this forum. I'm developing a CMS for my latest website. This CMS is also in PhP & MySQL. I'm done with the ADD section where the Admin can INSERT new records in Database but I'm stuck in the EDIT. I'm getting 2 problems over here. Below is the description: 1)The FIRST page will list all the records from the table which Admin can EDIT with CHECKBOX for each record to select. He can select one or more than one...
0
9001
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9584
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9345
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9257
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6811
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4716
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.