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
 Transferring some data

Author  Topic 

sqlbug
Posting Yak Master

201 Posts

Posted - 2009-07-14 : 15:53:46
I have to transfer data from a table where I have data columns for 24 hours of the day – to a table where there is just one column for the data. So data from 24 columns from the first table will go to 24 rows of the new table.
Each of the tables have same type of header tables. So, the old tables are like:
Header_Data - Header_NUM(PK), Header_TYPE (FK),Header_START_DATE],[ Header_START_TIME],[ Header_END_DATE],[ Header_END_TIME]

Detail_Data – DT_Header_NUM,DT_SAMPLE_TYPE,DT_PARAMETER,DT_UNITS,DT_METHOD, ,DT_HOUR1_VALUE, DT_HOUR1_FLAG,DT_HOUR2_VALUE,……………DT_HOUR23_VALUE,DT_HOUR24_VALUE.

New tables are as follows:

New_Header_Data – Same

New_Detail_Data - DATA_ID,DATA_SAMPLE_NUM,DATA_PARAMETER,DATA_METHOD,DATA_UNIT DATA_VALUE,DATA_FLAG

I need help to build this script, Thanks.

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2009-07-14 : 16:42:19
What version of SQL are you using? You might be able to use UNPIVOT or jsut simply use 24 UNION queries.
Go to Top of Page

sqlbug
Posting Yak Master

201 Posts

Posted - 2009-07-14 : 18:00:51
I am using 2005. Can you show me a UNPIVOT sample please? Thanks.
Go to Top of Page
   

- Advertisement -