2017-09-01 52 views
0

我有以下支點查詢:如何按訪問數據透視列中的月份名稱排序?

TRANSFORM Sum(Forecast.Openquantity) AS OpenQty 
SELECT Forecast.Material, Forecast.Description, Forecast.Unrestricted 
FROM Forecast 
GROUP BY Forecast.Material, Forecast.Description, Forecast.Unrestricted 
ORDER BY Forecast.Material, Forecast.Description, MonthName(Month([Forecast].[LoadingDate])) 
PIVOT MonthName(Month([Forecast].[LoadingDate])); 

,工作正常,但當月名稱(列行)是按字母順序排序,而不是按月份數。

上述查詢給我列的順序是:四月,八月,十二月,二月...

,我想了好幾個月的正常秩序:一月,二月,三月......

如何更改此查詢以便對月份名稱列進行正確排序?

回答

2

你不喜歡這樣:

PIVOT MonthName(Month([Forecast].[LoadingDate])) IN ("January","February", ... ,"December");