Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase «««678910

Sorting Months By Number (SQL Spackle) Expand / Collapse
Author
Message
Posted Tuesday, August 13, 2013 7:50 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, August 13, 2013 8:44 AM
Points: 5, Visits: 26
Thanks for following up and testing the different solutions Jeff - makes for interesting reading. The personal lesson for me from this is "test your code before posting". That way I could now be "N. North" rather than "N.North (corrected)".

Nick
Post #1483739
Posted Tuesday, August 13, 2013 8:40 AM
SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Monday, December 15, 2014 9:36 AM
Points: 652, Visits: 1,901
Yep. For single rows, that will work just fine. Try your code with a GROUP BY and a SUM on the Sale column and see what happens.


...below is my latest in the 'compatible' format - perhaps you can add to your collection, Jeff. Thanks....David.

--===== Query by dmckinney ==========================================================
-- (http://www.sqlservercentral.com/Forums/FindPost1480386.aspx)
SELECT
[Month] = DATENAME(m,DATEADD(m,DATEDIFF(m,0,SomeDateTime)%12,0)),
Amount = SUM(SomeAmount)
FROM #MyHead
WHERE SomeDateTime >= '2010' AND SomeDateTime < '2011' --changed dates to same as elsewhere
GROUP BY DATEDIFF(m,0,SomeDateTime)%12
ORDER BY DATEDIFF(m,0,SomeDateTime)%12
Post #1483778
Posted Tuesday, August 13, 2013 10:22 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Tuesday, August 13, 2013 10:22 PM
Points: 2, Visits: 1
Yes, agree
Post #1484065
« Prev Topic | Next Topic »

Add to briefcase «««678910

Permissions Expand / Collapse