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.
Author |
Topic |
sheridanbman
Starting Member
10 Posts |
Posted - 2010-08-19 : 19:13:05
|
Wondering if someone can help. Here is an example of my table structure.inputDate shipCleanAccuracy billCleanAccuracy10/3/2009 99.48 99.8710/10/2009 99.48 99.9710/17/2009 99.89 99.9710/24/2009 99.57 99.8710/31/2009 99.9 99.911/7/2009 99.97 99.9511/14/2009 99.93 99.6511/21/2009 99.96 99.9911/28/2009 99.81 99.9312/5/2009 99.93 99.9412/12/2009 99.87 99.9612/19/2009 99.94 99.9412/26/2009 99.96 99.981/2/2010 99.93 99.971/9/2010 99.76 99.971/16/2010 99.99 99.971/23/2010 100 99.881/30/2010 100 99.972/6/2010 99.94 99.91I was hoping to produce an output like this. --------------- 10/3/2009 10/10/200 10/17/2009shipCleanAccuracy 99.48 99.48 99.89billCleanAccuracy 99.87 99.97 99.97 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-08-19 : 19:28:22
|
you can use the PIVOT operator with Dynamic SQL KH[spoiler]Time is always against us[/spoiler] |
 |
|
sheridanbman
Starting Member
10 Posts |
Posted - 2010-08-19 : 19:32:31
|
khtan can i have shipCleanAccuracy and billCleanAccuracy as the rows? I couldn't seem to find away to do that dynamically with columns as the rows. |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-08-19 : 19:38:54
|
you will need to unpivot that first and then pivot again KH[spoiler]Time is always against us[/spoiler] |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-08-19 : 19:46:32
|
something to help you kick start ..select *from ( select * from yourtable unpivot ( value for typ in ([shipCleanAccuracy], [billCleanAccuracy]) ) up ) d pivot ( sum(value) for inputDate in ([10/03/2009], [10/10/2009], [10/17/2009]) ) p KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|