| Author |
Topic |
|
nt4vn
Yak Posting Veteran
98 Posts |
Posted - 2009-09-28 : 09:21:50
|
| Hi,I need to move suite number from address line 2 to address line 1, and keep street number on address line 2 (if there is a suite number in the mailing address). Do you have any coding that we can make it quick rather than manually fix each address.I already ran a sql statement to search for those address that had SUITE NUMBER on address line 2, but don't know if we can have a way to move that suite # to address line 1, and move street number to address line 2.FOR EXAMPLE: ADDRESS LINE 1: 123 SUNOCO STADDRESS LINE 2: SUITE 200CITY: MIAMISTATE: FLWould like to make it like: ADDRESS LINE 1: SUITE 200ADDRESS LINE 2: 123 SUNOCO STCITY: MIAMISTATE: FLAny input would appreciate...thanks, |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-09-28 : 09:46:14
|
| Table structure, sample data, etc., pleaseJimEveryday I learn something that somebody else already knew |
 |
|
|
smarty
Starting Member
13 Posts |
Posted - 2009-09-28 : 09:46:46
|
| You can do a update based on an inner join back onto the same table. Short form example belowUPDATE {YOUR_TABLE}SET {Address line 1 column} = T.{Extracted suite number from address 2 column}FROM {YOUR_TABLE} T-----------------------------------Free SQL server monitoring for DBA'swww.realsmartsoftware.co.uk |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-09-28 : 11:17:27
|
| Try thisDECLARE @temp varchar (50)DECLARE @Table TABLE (id int,add1 varchar(50),add2 varchar(50),city varchar(50),state char(2),zipcode char(5))INSERT INTO @TableSELECT 1234567,' ABC','SUITE 100','MENOMONEE FALLS','WI','53051' UNION ALLSELECT 1234568,' ABCD','SUITE 500','DULUTH','GA','30096' UNION ALLSELECT 1234569,' DCFE','SUITE 140','AMBLER','PA','19002' UNION ALLSELECT 1234570,' EDF','SUITE 314','KINGSTON','PA','18704' UNION ALLSELECT 1234571,' FGH','SUITE 111C','ALLENTOWN','PA','18103' UNION ALLSELECT 1234572,' IJK','SUITE 300','PHILADELPHIA','PA','19102'UPDATE @TABLE SET @temp = add1,add1 = add2,add2 = @tempselect * from @tableJimEveryday I learn something that somebody else already knew |
 |
|
|
nt4vn
Yak Posting Veteran
98 Posts |
Posted - 2009-09-28 : 11:59:11
|
Thanks for your input....I used your update function...and it worked well.UPDATE tableSET AD_STREET_1 = AD_STREET_2,AD_STREET_2 = AD_STREET_1WHERE ad_street_2 like 'Suite%'quote: Originally posted by jimf Try thisDECLARE @temp varchar (50)DECLARE @Table TABLE (id int,add1 varchar(50),add2 varchar(50),city varchar(50),state char(2),zipcode char(5))INSERT INTO @TableSELECT 1234567,' ABC','SUITE 100','MENOMONEE FALLS','WI','53051' UNION ALLSELECT 1234568,' ABCD','SUITE 500','DULUTH','GA','30096' UNION ALLSELECT 1234569,' DCFE','SUITE 140','AMBLER','PA','19002' UNION ALLSELECT 1234570,' EDF','SUITE 314','KINGSTON','PA','18704' UNION ALLSELECT 1234571,' FGH','SUITE 111C','ALLENTOWN','PA','18103' UNION ALLSELECT 1234572,' IJK','SUITE 300','PHILADELPHIA','PA','19102'UPDATE @TABLE SET @temp = add1,add1 = add2,add2 = @tempselect * from @tableJimEveryday I learn something that somebody else already knew
|
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-09-28 : 12:13:05
|
| Just run the update statement. I inserted the records in to a table variable because you didn't provide that, and I wanted to demonstrate that the solution works. You may also want to verify that the solution works on your data before running it.JimEveryday I learn something that somebody else already knew |
 |
|
|
nt4vn
Yak Posting Veteran
98 Posts |
Posted - 2009-09-28 : 12:20:45
|
Yes, I figured out after I sent previous note...but I used your update funtion...and it worked very well...that saved me a lot of time...:-)Thanks a bunch!quote: Originally posted by jimf Just run the update statement. I inserted the records in to a table variable because you didn't provide that, and I wanted to demonstrate that the solution works. You may also want to verify that the solution works on your data before running it.JimEveryday I learn something that somebody else already knew
|
 |
|
|
|
|
|