访问时将月份编号转换为月份名称函数

Convert Month Number to Month Name Function on Access

我的好参考是 Convert Month Number to Month Name Function in SQL

到目前为止我有:

SELECT Detail.ItemCode, SUM(Detail.QuantityOrdered) AS Total_Quantity, Header.OrderDate
FROM Detail INNER 
JOIN rHeader ON Detail.SalesOrderNo = Header.SalesOrderNo
WHERE Header.OrderDate >= dateadd("m", -4, Date())
GROUP BY Detail.ItemCode, OrderDate
ORDER BY SUM(Detail.QuantityOrdered) DESC;

它过滤了我的结果,它只显示了今天月份的最后四个月的结果。

我想要每个月的销售数量总和,以及它的月份命名函数。

例如:

ItemCode | 10 or October | 11  |  12 |  1     
   PM    |        200    | 200 | 200 | 200 

Update: I did try the following line of code, but my date is in the form of 12/26/2016. Is there anyway that I can play with it?? Thank you!

 SELECT MonthName( month , DateAdd( month , @MonthNumber , 0 ) - 1 )

在 Access 查询中,您应该能够使用 MonthName 函数将月份编号(例如 10)转换为月份名称(例如 'October')。

例如,如果您查询 return 是出生日期 (DOB)...

SELECT [DOB] FROM [Clients] WHERE [ID]=1
DOB
----------
1977-05-15

..你可以return他们出生的月份名称

SELECT MonthName(Month([DOB])) AS MonthOfBirth FROM [Clients] WHERE [ID]=1
MonthOfBirth
------------
May