Link to home
Start Free TrialLog in
Avatar of Thomas Stockbruegger
Thomas StockbrueggerFlag for Germany

asked on

SQL order of month and year

sql.Format("SELECT DATEPART(year,A.Lieferscheindatum)AS year,\
            DATEPART(month,A.Lieferscheindatum)AS month,\
            SUM(B.Einheitbez13wert)AS Gewicht\
            FROM Lieferscheine AS A , Lieferscheinpositionen AS B\
                      WHERE A.LieferscheinNr=B.LieferscheinNr AND A.LieferscheinNr<200000\
           GROUP BY DATEPART(month,A.Lieferscheindatum),\
            DATEPART(year,A.Lieferscheindatum)\
            ORDER by DATEPART(month,A.Lieferscheindatum)ASC,\
            DATEPART(year,A.Lieferscheindatum)DESC");

Hello,
In my SQL Table I have data from 2006 Januar till today 2013 May.
With my SQL code I will get the data in this order

        year   month
        2013  Jan
       2012  Jan
       2011  Jan
         .
         .
         .
       2006 Jan

       2013  Feb
       2012  Feb
       2011      Feb  
 .
 .
 .
2006 Feb  and so on


 

But I would like to get the following order:
2006      Jan
2006      Feb
2006        Mar
2006        Apr
.
.
.
.
.
.
.
2013     May


Thank you for your help.
500 points with a solution.
Best regards,
Thomas
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Thomas Stockbruegger

ASKER

thank you, that was easy......got a bit rusty over time with SQL