Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 every two rows

Author  Topic 

Yellowdog
Starting Member

34 Posts

Posted - 2009-12-10 : 11:43:50
I have a table with one column and with Name in one row followed by address (city state zip) in the next row.

I need to parse this into another table with a simple record in each row
name address city state zip.

parsing the name and address into separate columns is not a problem, what is is getting the every other row into one row.

Any help would be great!

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-12-10 : 12:02:43
This is an absolutely useless design. Without any way to tie a name record to an address record there is no way to guarantee correct results.

The reason is because the sort order is not guaranteed to be in the order you want without specifying an ORDER BY clause. So a name may end up being matched with the wrong address.

You can identify the address records WHERE fieldName LIKE'%[0123456789]%' but how to tie it to the proper name...

If this perhaps came from an Excel sheet, go back to Excel and add an ID column, and put incrementing #s in it. Then we can help you with something that'll work
Go to Top of Page

Yellowdog
Starting Member

34 Posts

Posted - 2009-12-10 : 12:05:34
yah thats the problem, this is a file downloaded off an old unix system and comes in as a txt file with the name in one row and address in the following row.

so I need to find a way to get this data in a workable table.
Go to Top of Page

RyanRandall
Master Smack Fu Yak Hacker

1074 Posts

Posted - 2009-12-10 : 12:21:25
Maybe just my preference, but I'd process the file using some procedural language to start with. Here's one example I just found:

http://www.lockergnome.com/sqlsquirrel/2007/12/18/how-to-parse-a-text-file-with-vbscript

Edit: link wasn't posting properly - okay now, I think

Ryan Randall - Yak of all trades
Solutions are easy. Understanding the problem, now, that's the hard part.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-12-10 : 12:27:25
first pop it into Excel. Then add a column and put numbers in it. then import to SQL with the #s. Then it's easy -- odd is name, even is address
Go to Top of Page
   

- Advertisement -