order by desc and asc on same column

  • I have a table has data of all months. i want to have this table data in the form as first it lists data

    from 1 month to current month then current month+1 to end of the year.

    any help

  • Please show us your table, the data in it, and the results you want to see.

    Better yet, give us the DDL for the table, INSERT statements for your data, the SQL you have tried, and the results you want to see.

    Help us help you.

  • sqlinterset (6/22/2015)


    I have a table has data of all months. i want to have this table data in the form as first it lists data

    from 1 month to current month then current month+1 to end of the year.

    any help

    Current month +1 to end of the year has not occurred yet.



    Alvin Ramard
    Memphis PASS Chapter[/url]

    All my SSC forum answers come with a money back guarantee. If you didn't like the answer then I'll gladly refund what you paid for it.

    For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]

  • LoudClear (6/22/2015)


    Please show us your table, the data in it, and the results you want to see.

    Better yet, give us the DDL for the table, INSERT statements for your data, the SQL you have tried, and the results you want to see.

    Help us help you.

    +1.......cant seen to fathom what the OP question is asking.

    though having said that.....i was away the day they taught mindreading;-)

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • sqlinterset (6/22/2015)


    I have a table has data of all months. i want to have this table data in the form as first it lists data

    from 1 month to current month then current month+1 to end of the year.

    any help

    not at all sure what you are asking...but (as a guess) is this anything related to month to date / year to date sales figures and previous year comparisons and budgets?

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • If I understand what you are asking, try the following.

    SELECT *

    FROM your_table

    ORDER BY CASE WHEN <your criteria here> THEN your_date_field ELSE '9999-12-31' END ASC

    , your_date_field DESC

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • So, are we pulling hen's teeth again or are you going to actually help us help you rather than hope one of us makes a lucky shot in the dark??

  • sqlinterset (6/22/2015)


    I have a table has data of all months. i want to have this table data in the form as first it lists data

    from 1 month to current month then current month+1 to end of the year.

    any help

    "1[st] month to current month, current month+1 to end of the year" is the same month ASC order.

  • Attached is the new file which has data in present format and required format. I tried to do through SQL and data comes in ordered way but as soon as data comes in excel pivot tables, its not ordered so may be if there is any excel feature to do it.

    As said earlier currently data is coming in usual order as from Jan to end of the year. However data is needed as Jul to Dec and then Jan to Current month (Jun) .

  • sqlinterset (6/22/2015)


    I have a table has data of all months. i want to have this table data in the form as first it lists data

    from 1 month to current month then current month+1 to end of the year.

    any help

    Add the year to your data set.

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • I have attached the file above to show what i need. Hope this helps. Thanks

  • this makes no sense without years. Are you saying that you'd need Jul '14 through Dec '14 and then Jan '15 through Jun '15?

    Or are you saying a rolling year across the months, based on today? There is no ordering to the data in a table, so without a year, and without trimming this to 12 rows only, you couldn't do it.

    However if there are just 12 rows, you could assign month numbers, and then add or subtract for the month numbers either before or after the current month to set an ordering column.

  • ChrisM@Work (6/23/2015)


    sqlinterset (6/22/2015)


    I have a table has data of all months. i want to have this table data in the form as first it lists data

    from 1 month to current month then current month+1 to end of the year.

    any help

    Add the year to your data set.

    Sounds like you need to use a calendar table. This looks a bit like fiscal year to me.

    http://qa.sqlservercentral.com/blogs/dwainsql/2014/03/30/calendar-tables-in-t-sql/[/url]

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • sqlinterset (6/23/2015)


    I have attached the file above to show what i need. Hope this helps. Thanks

    Yes I know, I saw it. You need the year as well as the month in your data set.

    Do you need help with getting the year as a column into your data set?

    Year Month rn

    2014 JUL 27

    2014 28

    2014 29

    2014 30

    2014 AUG 31

    2014 32

    2014 33

    2014 34

    2014 SEP 35

    2014 36

    2014 37

    2014 38

    2014 39

    2014 OCT 40

    2014 41

    2014 42

    2014 43

    2014 NOV 44

    2014 45

    2014 46

    2014 47

    2014 DEC 48

    2014 49

    2014 50

    2014 51

    2014 52

    2015 Jan 1

    2015 2

    2015 3

    2015 4

    2015 Feb 5

    2015 6

    2015 7

    2015 8

    2015 Mar 9

    2015 10

    2015 11

    2015 12

    2015 13

    2015 APR 14

    2015 15

    2015 16

    2015 17

    2015 MAY 18

    2015 19

    2015 20

    2015 21

    2015 JUN 22

    2015 23

    2015 24

    2015 25

    2015 26

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Is this question based on the output from here?

Viewing 15 posts - 1 through 15 (of 27 total)

You must be logged in to reply to this topic. Login to reply