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://www.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?

    YearMonthrn

    2014JUL27

    201428

    201429

    201430

    2014AUG31

    201432

    201433

    201434

    2014SEP35

    201436

    201437

    201438

    201439

    2014OCT40

    201441

    201442

    201443

    2014NOV44

    201445

    201446

    201447

    2014DEC48

    201449

    201450

    201451

    201452

    2015Jan1

    20152

    20153

    20154

    2015Feb5

    20156

    20157

    20158

    2015Mar9

    201510

    201511

    201512

    201513

    2015APR14

    201515

    201516

    201517

    2015MAY18

    201519

    201520

    201521

    2015JUN22

    201523

    201524

    201525

    201526

    “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