Solved

SQL order of month and year

Posted on 2013-05-14
2
438 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
2 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
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
Comment Utility
thank you, that was easy......got a bit rusty over time with SQL
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how the fundamental information of how to create a table.

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now