Solved

SQL order of month and year

Posted on 2013-05-14
2
479 Views
Last Modified: 2013-05-14
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
0
Comment
Question by:tsp2002
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39164334
Flip your ORDER BY clause around and change the sort order for the year:

ORDER by DATEPART(year,A.Lieferscheindatum)ASC,
         DATEPART(month,A.Lieferscheindatum)ASC");

Open in new window

0
 

Author Closing Comment

by:tsp2002
ID: 39164417
thank you, that was easy......got a bit rusty over time with SQL
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question