Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bring flat file to relational database 1

Status
Not open for further replies.

Niv3k

Programmer
Jul 11, 2001
350
US
I have a flat file that has several non-relational fields, such city_due_1, city_due_2, city_due_3, city_due_4.

There is also garbage 1-4, sewer 1-4, and water 1-4.

I would like to normalize this a little by bringing these fields into their own seperate tables, for example:
bill_num int
quarter tinyint (1 - 4)
city_due currency

Any ideas on how to do this without using a cursor?

thanks, Kevin
 
Are you importing the data into a staging table in SQL before INSERTing the data into your "real" data tables?

If so, use a UNION or perform separate INSERT...SELECT statements:

INSERT INTO CityDue (BillNum, Quarter, City_Due)
SELECT BillNum, Quarter, City_Due_1
FROM StagingTable WHERE City_Due_1 IS NOT NULL
UNION
SELECT BillNum, Quarter, City_Due_2
FROM StagingTable WHERE City_Due_2 IS NOT NULL
UNION
SELECT BillNum, Quarter, City_Due_3
FROM StagingTable WHERE City_Due_3 IS NOT NULL
UNION
SELECT BillNum, Quarter, City_Due_4
FROM StagingTable WHERE City_Due_4 IS NOT NULL


I hope this helps. Good luck!



--Angel [rainbow]
-----------------------------------
Every time I lose my mind, I wonder
if it's really worth finding.
 
so THATS what the union operator does... Boy this would've come in handy years ago.

Thanka!

Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top