2016-04-26 47 views

回答

0

似乎是一個黑客的一點點,但提供正確的結果。

DECLARE @myDate DATETIME; SET @myDate = '3/15/16' 
SELECT 
UPPER(LEFT(DATENAME(MONTH, DATEADD(MONTH, MONTH(@MyDate), -1)), 3) + '-' 
    + LEFT(DATENAME(MONTH, DATEADD(MONTH, MONTH(@MyDate) + 2, -1)), 3)) AS Q1, 
UPPER(LEFT(DATENAME(MONTH, DATEADD(MONTH, MONTH(@MyDate) + 3, -1)), 3) + '-' 
    + LEFT(DATENAME(MONTH, DATEADD(MONTH, MONTH(@MyDate) + 5, -1)), 3)) AS Q2, 
UPPER(LEFT(DATENAME(MONTH, DATEADD(MONTH, MONTH(@MyDate) + 6, -1)), 3) + '-' 
    + LEFT(DATENAME(MONTH, DATEADD(MONTH, MONTH(@MyDate) + 8, -1)), 3)) AS Q3, 
UPPER(LEFT(DATENAME(MONTH, DATEADD(MONTH, MONTH(@MyDate) + 9, -1)), 3) + '-' 
    + LEFT(DATENAME(MONTH, DATEADD(MONTH, MONTH(@MyDate) + 11, -1)), 3)) AS Q4 
相關問題