Group by DateTime cut-off point

0

Please login or register to vote for this query.

(click on this box to dismiss)

Meta Stack Exchange

Q&A about the Stack Exchange Network

;WITH Orders AS (
    	SELECT * FROM (VALUES
    		(CAST('2012-01-01 06:10:01' AS DATETIME), 2)
    		, ('2012-01-01 08:10:01', 2)
    		, ('2012-01-01 10:10:01', 4)
    		, ('2012-01-02 08:00:07', 4)
    		, ('2012-01-02 10:00:07', 4)
    	) AS Orders (DateReceived, Total)		
    )
    SELECT	CONVERT(varchar, DATEADD(hour, -10, [DateReceived]), 111) AS [dt_DateReceived]
    		, SUM([Total]) AS perday
    FROM	[Orders] 
    GROUP BY 
    		CONVERT(varchar, DATEADD(hour, -10, [DateReceived]), 111)
    ORDER BY 
    		1

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results
:records returned in :time ms:cached