所以我在SSRS 2008 R2中制作了一个图表,无论出于何种原因,轴标签拒绝显示为日期值,而是显示为他们所代表的月份数(对于例如,1月显示为" 1",2月显示为" 2"等。)。我已经弄乱了图表的各种属性,来自" Axis Options"到"数字"标签。不幸的是,迄今为止没有任何工作。对图表只进行了一次其他更改,即类别组中的排序,以便图表可以从不同年份提取数据。这是获取图表数据的代码:
SELECT Year = DATEPART(YEAR, date1),
date1 = DATEPART(MONTH, date1),
sum(qty) as TotalQTY
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)
谢谢。
答案 0 :(得分:0)
您的查询可以更改为包含月份名称。绑定到图表时,您可以使用名称而不是数字,以便轴可以显示月份名称而不是月份编号。
以下是如何获取月份名称的示例:
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
您还可以查看此帖子,了解在不使用案例陈述的情况下获取月份名称的方法:Convert Month Number to Month Name Function in SQL