Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Microsoft SQL Server > Re: Using UPDAT...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 11 Topic 11202 of 11422
Post > Topic >>

Re: Using UPDATE to sequentially abbreviate address information

by Chris H <chollstein@[EMAIL PROTECTED] > Jul 2, 2008 at 01:54 PM

On Jul 2, 4:12=A0pm, "Roy Harvey (SQL Server MVP)" <roy_har...@[EMAIL PROTECTED]
>
wrote:
> First of all get rid of the TOP (100) PERCENT nonsense. =A0While 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. =A0If 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_Fix
> SET address_line_1_fix =3D
> =A0 =A0 =A0 =A0REPLACE(
> =A0 =A0 =A0 =A0REPLACE(
> =A0 =A0 =A0 =A0REPLACE(
> =A0 =A0 =A0 =A0REPLACE(address_line_1,
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0'Boulevard','Blvd'),
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0'Street','St'),
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0'Avenue','Ave'),
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0'Road','Rd')
> WHERE (address_line_1 like '%Road%'
> OR =A0 =A0 address_line_1 like '%Avenue%'
> OR =A0 =A0 address_line_1 like '%Street%'
> OR =A0 =A0 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
re****ting 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)
=2E....
(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_Fix
SET address_line_1_fix =3D REPLACE(address_line_1_fix,'Street','St')
WHERE address_line_1_fix like '%Street%'
UPDATE dbo.All_Client_Companies_For_Fix
SET address_line_1_fix =3D
REPLACE(address_line_1_fix,'Boulevard','Blvd')
WHERE address_line_1_fix like '%Boulevard%'
GO
 




 11 Posts in Topic:
Using UPDATE to sequentially abbreviate address information
Chris H <chollstein@[E  2008-07-02 12:26:57 
Re: Using UPDATE to sequentially abbreviate address information
"Roy Harvey (SQL Ser  2008-07-02 16:12:10 
Re: Using UPDATE to sequentially abbreviate address information
--CELKO-- <jcelko212@[  2008-07-02 13:21:46 
Re: Using UPDATE to sequentially abbreviate address information
Iain Sharp <iains@[EMA  2008-07-04 12:32:54 
Re: Using UPDATE to sequentially abbreviate address information
Ed Murphy <emurphy42@[  2008-07-04 13:01:27 
Re: Using UPDATE to sequentially abbreviate address information
Iain Sharp <iains@[EMA  2008-07-07 09:45:16 
Re: Using UPDATE to sequentially abbreviate address information
Gert-Jan Strik <sorry@  2008-07-02 22:27:27 
Re: Using UPDATE to sequentially abbreviate address information
Chris H <chollstein@[E  2008-07-02 13:54:25 
Re: Using UPDATE to sequentially abbreviate address information
jhofmeyr@[EMAIL PROTECTED  2008-07-07 08:49:21 
Re: Using UPDATE to sequentially abbreviate address information
Erland Sommarskog <esq  2008-07-07 22:08:51 
Re: Using UPDATE to sequentially abbreviate address information
--CELKO-- <jcelko212@[  2008-07-08 08:45:35 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Oct 12 21:09:40 CDT 2008.