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 |
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2011-09-08 : 10:20:12
|
| Hello therei have the following example pivot script that works fine.Select company_name, [2006-03-06], [2008-07-07]from (select company_name, status_date, [total_amount] from pivotTest ) AS sourcespivot (sum(total_amount) for status_date in ([2006-03-06], [2008-07-07] ))as pivis there a way i can use the year function as the columns.egSelect company_name, year(status_date)=2006, year(status_date)=2008from (select company_name, status_date, [total_amount] from pivotTest ) AS sourcespivot (sum(total_amount) for status_date in (year(status_date)=2006, year(status_date)=2006 ))as pivkind regardsRobMCTS / MCITP certified |
|
|
masterdineen
Aged Yak Warrior
550 Posts |
Posted - 2011-09-08 : 10:29:25
|
| its ok sorted it, thank youall it did was select year(status_date) firstSelect company_name, [2006], [2008]from (select company_name, year(status_date) as 'status date', [total_amount] from pivotTest ) AS sourcespivot (sum(total_amount) for status_date in ([2006], [2008]))as piv |
 |
|
|
|
|
|
|
|