Solved

SQL order of month and year

Posted on 2013-05-14
2
475 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Viewers will learn how the fundamental information of how to create a table.

733 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