April 1, 2014 at 11:46 am
PS: The attachment has a screenshot of the tables described below which is easier to read
Hi All,
I am stuck on finding a solution to transpose source data from a system via a metadata look-up table into a destination table. I need a method to transpose/pivot the source data into columns (which are by various data-types). The datatypes for each column are listed in a metadata table.
Source Data Table:
Table Name: Source
SrcID AGE City Date
01 32 London 01-01-2013
02 35 Lagos 02-01-2013
03 36 NY 03-01-2013
Metadata Table:
Table Name:Metadata
MetaID Column_Name Column_type
11 AGE col_integer
22 City col_character
33 Date col_date
Destination table:
The source data to be loaded into the destination table(as shown below):
Table Name: Destination
SrcID MetaID col_int col_char col_date
01 11 32 - -
01 22 - London -
01 33 - - 01-01-2013
02 11 35 - -
02 22 - Lagos -
02 33 - - 02-01-2013
03 11 36 - -
03 22 - NY -
03 33 - - 03-01-2013
Any help would be much appreciated.
Thank you,
Aarion
April 1, 2014 at 8:12 pm
Luis Cazares (4/1/2014)
I would unpivot[/url] the source table, join it with the metadata table, use cross tabs[/url] to obtain the desired result and run away from that horrible design.That destination table looks like real horror for any RDBMS.
Horror?!? I LOVE designs like that ... they make the consultant in me go "kaaAACHIIINNNGGG"!! 😀
Best,
Kevin G. Boles
SQL Server Consultant
SQL MVP 2007-2012
TheSQLGuru on googles mail service
April 1, 2014 at 11:41 pm
AarionSSQL (4/1/2014)
PS: The attachment has a screenshot of the tables described below which is easier to readHi All,
I am stuck on finding a solution to transpose source data from a system via a metadata look-up table into a destination table. I need a method to transpose/pivot the source data into columns (which are by various data-types). The datatypes for each column are listed in a metadata table.
Source Data Table:
Table Name: Source
SrcID AGE City Date
01 32 London 01-01-2013
02 35 Lagos 02-01-2013
03 36 NY 03-01-2013
Metadata Table:
Table Name:Metadata
MetaID Column_Name Column_type
11 AGE col_integer
22 City col_character
33 Date col_date
Destination table:
The source data to be loaded into the destination table(as shown below):
Table Name: Destination
SrcID MetaID col_int col_char col_date
01 11 32 - -
01 22 - London -
01 33 - - 01-01-2013
02 11 35 - -
02 22 - Lagos -
02 33 - - 02-01-2013
03 11 36 - -
03 22 - NY -
03 33 - - 03-01-2013
Any help would be much appreciated.
Thank you,
Aarion
If you want coded help, please see the first link under "Helpful Links" in my signature line below. You came really close... just need to push it over the edge to get the best help for your question.
--Jeff Moden
Change is inevitable... Change for the better is not.
April 2, 2014 at 3:15 am
Thank you Luis .. apologies for the late reply. I had no internet access overnight but back in the office now.
I have done this:
Unpivot data
Left Join to Metadata table
Pivot data
it worked.
Many thanks for your help on this!
As for the design I am totally against it but there are times when you just have to build a sample solution to prove your point and this is one of them!
April 2, 2014 at 3:16 am
It is a complete horror! Now to model it and prove my point! 😀
April 2, 2014 at 3:18 am
Thanks Jeff, I was just after the idea. I have got the code working after Luis comments.
Thank you to all for replying!
aarionsql (4/2/2014)
Thank you Luis .. apologies for the late reply. I had no internet access overnight but back in the office now.I have done this:
Unpivot data
Left Join to Metadata table
Pivot data
it worked.
Many thanks for your help on this!
As for the design I am totally against it but there are times when you just have to build a sample solution to prove your point and this is one of them!
April 2, 2014 at 9:29 am
I'm glad that you could get it done and it's even better to know that you're aware of this terrible design.
Good luck with this project (you'll need it).
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply