I am hoping someone can help me with a procedure. I know the result involves a pivot table, however I don't completely understand how Pivot/Unpivot works or whow to write one:
Here's my scenatio: I have 2 columns of data by 48 rows.
Column A and Column B
Time Data
00:00:00 835
00:30:00 763
01:00:00 669
01:30:00 630
02:00:00 588
02:30:00 585
03:00:00 591
03:30:00 570
04:00:00 616
04:30:00 690
....
I want to turn this into a table that has 1 row of data that is 48 columns wide. The previous Column A would now become the 48 Column headings and Column B would be the data in the Row.
00:00:00 00:30:00 01:00:00 01:30:00.....
835 763 669 630 ....
Any ideas?
You are correct, Jim: You can use a PIVOT for this if you are using SQL Server 2000. Something like this:
|||Thanks, I was able to get it to work. I really appreciate the help|||select [00:30:00],
[01:00:00],
...
[23:30:00]
from YourTable
pivot ( sum([Data]) for [Time] in
( [00:00:00],
[00:30:00],
...
[23:30:00]
) ) piv
Jim:
When I was getting ready for work I had convinced myself that I had misunderstood the question. I had figured that what you wanted was to establish these partitions and then summarize the data as a pivot and that this wasn't going to work correctly.
I'm glad my second thoughts were wrong!
:-)
No comments:
Post a Comment