您的查询可以更改为包含月份的名称。绑定图表时可以使用名称而不是数字,这样轴就可以显示月份名称而不是月份数字。
下面是如何获取月份名称的示例:
SELECT Year = DATEPART(YEAR, date1),
date1 = DATEPART(MONTH, date1),
SUM(qty) as TotalQTY,
CASE -- Case statement translates the integer of the month into the name of the month
WHEN DATEPART(MONTH, date1) = 1 THEN 'January'
WHEN DATEPART(MONTH, date1) = 2 THEN 'February'
WHEN DATEPART(MONTH, date1) = 3 THEN 'March'
WHEN DATEPART(MONTH, date1) = 4 THEN 'April'
WHEN DATEPART(MONTH, date1) = 5 THEN 'May'
WHEN DATEPART(MONTH, date1) = 6 THEN 'June'
WHEN DATEPART(MONTH, date1) = 7 THEN 'July'
WHEN DATEPART(MONTH, date1) = 8 THEN 'August'
WHEN DATEPART(MONTH, date1) = 9 THEN 'September'
WHEN DATEPART(MONTH, date1) = 10 THEN 'October'
WHEN DATEPART(MONTH, date1) = 11 THEN 'November'
WHEN DATEPART(MONTH, date1) = 12 THEN 'December'
ELSE ''
END AS 'name_of_month'
FROM TableMain
WHERE Tablemain.date1 between @startdate and @enddate and Tablemain.fillerparam in(@fillerparam) and Tablemain.filler2 in (@filler2)
GROUP BY DATEPART(MONTH, date1), DATEPART(YEAR, date1),
CASE -- Add the case statement to the GroupBy so that it still groups as expected
WHEN DATEPART(MONTH, date1) = 1 THEN 'January'
WHEN DATEPART(MONTH, date1) = 2 THEN 'February'
WHEN DATEPART(MONTH, date1) = 3 THEN 'March'
WHEN DATEPART(MONTH, date1) = 4 THEN 'April'
WHEN DATEPART(MONTH, date1) = 5 THEN 'May'
WHEN DATEPART(MONTH, date1) = 6 THEN 'June'
WHEN DATEPART(MONTH, date1) = 7 THEN 'July'
WHEN DATEPART(MONTH, date1) = 8 THEN 'August'
WHEN DATEPART(MONTH, date1) = 9 THEN 'September'
WHEN DATEPART(MONTH, date1) = 10 THEN 'October'
WHEN DATEPART(MONTH, date1) = 11 THEN 'November'
WHEN DATEPART(MONTH, date1) = 12 THEN 'December'
ELSE ''
END
ORDER BY date1 -- Added order by to make sure that records are sorted in the report by date and not by alphabetic name of month
您还可以查看这篇文章,了解不使用 case 语句获取月份名称的方法:Convert Month Number to Month Name Function in SQL