报告排序月份数字不正确

时间:2017-09-09 01:45:29

标签: c# sql rdlc

这很奇怪,因为我之前用了几年/几个月制作了矩阵,但现在由于某种原因这几个月了:1,10,11,12,3,4,5等......

问题:

The problem

SQL Server中的排序很好,图表显示的数据是正确的。它在我用其他专栏试过之前就已经有效了,但现在它搞得一团糟。它使用DataSet作为具有以下内容的源:

Godina(年)为Int32, Mjesec(月)为Int32和 BrojNarudzbi(订单数量)为Int32,按此顺序列在DataTable中。这个程序是我从中获取记录的地方,如果它有帮助:

begin
Select Count(NarudzbeID) as 'BrojNarudzbi', Month(N.DatumNarudzbe) as 'Mjesec', Year(N.DatumNarudzbe) as 'Godina'
from Narudzbe as N
Group by  Year(N.DatumNarudzbe), Month(N.DatumNarudzbe)
Order by Year(N.DatumNarudzbe), Month(N.DatumNarudzbe)

同样,显示的数据是正确的,因为某些奇怪的原因,几个月没有被分类。

1 个答案:

答案 0 :(得分:2)

验证此列的数据集中的数据类型。

字母顺序就好像有字符串一样。尝试在一个数字月之前添加'0'

begin
Select Count(NarudzbeID) as 'BrojNarudzbi', 
  right('0'+cast(Month(N.DatumNarudzbe) as varchar(2)),2) as 'Mjesec', 
  Year(N.DatumNarudzbe) as 'Godina'
from Narudzbe as N
Group by  Year(N.DatumNarudzbe), Month(N.DatumNarudzbe)
Order by Year(N.DatumNarudzbe), Month(N.DatumNarudzbe)