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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Normalised to Flat file format dynamically

Author  Topic 

dshelton
Yak Posting Veteran

73 Posts

Posted - 2003-04-30 : 21:48:03
I currently have normalised table that I need to transform in to a flat file table. I would like to do this dynamically as field names and number of fields can vary. Besides writing out a loop, I was wondering if anyone had any better or quicker ideas.

This table:

Key Att Order
A X 1
A Y 2
A Z 3

Needs to become:

Key Att1 Att2 Att3
A X Y Z

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-04-30 : 21:55:36
Look at Rob's wonderful DYNAMIC SQL CROSS TAB stored procedure, in the articles. Denormalizing data in this manner is often refered to a Cross tabbing.

here's the link:
http://www.sqlteam.com/item.asp?ItemID=2955

Also, read all of the comments (make sure you have some time!) for variations on his techinque and other ideas.

(my comment -- #60 !! -- shows a pretty short and very flexible method that lets you pivot non-numeric columns and use functions like MIN() or MAX(), and also perform multiple pivots)

- Jeff

Edited by - jsmith8858 on 04/30/2003 21:59:10
Go to Top of Page
   

- Advertisement -