我正在尝试这个,但它会以意想不到的“顺序返回结果......应该
2013-01,2013-02,2013-03等view_YearWeeks是一个视图,选择DISTINCT YearWeek从销售表中订购ASC ...如果执行它正确排序值,但在此
Select @colWeeks = isnull(@colWeeks + ', ','') + QUOTENAME(YearWeek)
from
(select YearWeek
from dbo.YearWeeks) as weeks
它返回
[2014-33], [2014-48], [2013-13], etc
我该如何解决?
答案 0 :(得分:1)
使用Order By
在SQL Server中订购记录。
Declare @colWeeks nvarchar(1000) = N'';
Select @colWeeks = isnull(@colWeeks + ', ','') + QUOTENAME(YearWeek.YearWeek)
From YearWeek
Order By YearWeek.YearWeek;