ORDERING OF DATA

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • T.S.Negi

    ORDERING OF DATA

    HOW TO ORDER THIS DATA.

    MONTH-YEAR
    10-2003
    10-2020
    11-2003
    3 -2003
    4 -2003
    5 -2003
    6 -2003
    7 -2003
    8 -2003
    9 -2003


    THANX IN ADV.

    tilak.negi@mind-infotech.com
  • David Portas

    #2
    Re: ORDERING OF DATA

    If the data you posted represents the base data in a table then I suggest
    you redesign the table. You have a problem with sorting because this is a
    non-atomic column. Try using two integer columns or a single date column:

    CREATE TABLE Sometable (monthno INTEGER NOT NULL (CHECK monthno BETWEEN 1
    AND 12), yearno INTEGER NOT NULL CHECK (yearno BETWEEN 2000 AND 2100), ...)

    SELECT CAST(monthno AS CHAR(2))+'-'+CAST(yearno AS CHAR(4))
    FROM Sometable
    ORDER BY yearno, monthno

    or:

    CREATE TABLE Sometable (datecol DATETIME NOT NULL, ...)

    SELECT CAST(MONTH(date col) AS CHAR(2))+'-'+CAST(YEAR(dat ecol) AS CHAR(4))
    FROM Sometable
    ORDER BY datecol

    --
    David Portas
    ------------
    Please reply only to the newsgroup
    --


    Comment

    • DHatheway

      #3
      Re: ORDERING OF DATA

      You must explain this a little more completely to get some help. You could
      post the table definition of your table, for a start.

      I suspect you can get what you want by sorting on an expression or maybe a
      function but I can't be sure.

      "T.S.Negi" <tilak.negi@min d-infotech.com> wrote in message
      news:a1930058.0 311122130.21efb a59@posting.goo gle.com...[color=blue]
      > HOW TO ORDER THIS DATA.
      >
      > MONTH-YEAR
      > 10-2003
      > 10-2020
      > 11-2003
      > 3 -2003
      > 4 -2003
      > 5 -2003
      > 6 -2003
      > 7 -2003
      > 8 -2003
      > 9 -2003
      >
      >
      > THANX IN ADV.
      >
      > tilak.negi@mind-infotech.com[/color]


      Comment

      Working...