你能不能帮我硬编码到CalendarMonth排序下面的T-SQL SELECT语句中,所以当有人查询数据时,它会出现1月,2月而不是4月,8月。我已经为FinancialMonth行做了这个,但是在CalendarMonth。
BEGIN
INSERT INTO Time3(Date,CalendarYear,CalendarMonth,FinancialYear,FinancialMonth)
SELECT
@StartDate Date,YEAR(@StartDate) AS CalendarYear,
DATENAME(MONTH,@StartDate) AS CalendarMonth,
YEAR(Dateadd(MONTH,-3,@StartDate)) AS FinancialYear,
'Period ' + RIGHT('0' + CAST(MONTH(Dateadd(MONTH, -3,@StartDate)) AS VARCHAR(2)),2) AS FinancialMonth
SET @StartDate = DATEADD(dd,1,@StartDate)
END
答案 0 :(得分:2)
试试这个:
ORDER BY MONTH(@StartDate)
MONTH是一个函数,它返回一个表示指定日期月份的整数。 http://msdn.microsoft.com/ru-ru/library/ms187813.aspx
答案 1 :(得分:0)
只需在查询中添加一个额外的列,如下所示,只需将@Month替换为您的变量:
CASE @Month
WHEN 'January' THEN 1
WHEN 'February' THEN 2
WHEN 'March' THEN 3
WHEN 'April' THEN 4
WHEN 'May' THEN 5
WHEN 'June' THEN 6
WHEN 'July' THEN 7
WHEN 'August' THEN 8
WHEN 'September' THEN 9
WHEN 'October' THEN 10
WHEN 'November' THEN 11
WHEN 'December' THEN 12
END as MonthOrder
然后在你的ORDER BY子句中,按此列命令