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 |
|
Chamark
Starting Member
28 Posts |
Posted - 2010-04-13 : 14:50:27
|
| Beginner using MS-SQL2005Would it be possible to PIVOT the results of this statement to have the months show as columns? Any help is greatly appreciatedResults should look like thisJan Feb Mar Apr May Jun Jul . . .Current Yr Actual xxx xxx xxx xxx xxx xxx xxxCurrent Yr Target xxx xxx xxx xxx xxx xxx xxxCurrent Yr Forecst xxx xxx xxx xxx xxx xxx xxx...SELECT LEFT(DATENAME(month,YearMonth),3),k.[Actual_Month],[Target_Month],[Forecast_Month],t.Actual_Month AS PYA ,k.[Actual_YTD],[Forecast_YTD],[Target_YTD],v.Actual_YTD AS [YTD PYA]FROM [SPARS].[dbo].[t_kpi_Data] kOUTER APPLY (Select Actual_MonthFROM [SPARS].[dbo].[t_kpi_Data] WHERE YearMonth=DATEADD(yy,-1,k.YearMonth) AND DataSource_ID = k.DataSource_ID)tOUTER APPLY (Select Actual_YTDFROM [SPARS].[dbo].[t_kpi_Data] WHERE YearMonth=DATEADD(yy,-1,k.YearMonth) AND DataSource_ID = k.DataSource_ID)vWHERE k.YearMonth Between '01/01/2010' AND '12/31/2010'AND k.DataSource_ID = '629' |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-13 : 23:50:22
|
| its possible but you seem to have more than 1 month columns. so on which column basis you want to do pivot? some sample data of your query will also help------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|
|