Consulting

Results 1 to 4 of 4

Thread: Solved: sql qurey to arrange by names

  1. #1
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location

    Solved: sql qurey to arrange by names

    i have month table with data type varchar

    month1
    January
    march
    December
    February
    October
    September
    may
    march

    i want sql query to arrange month according to month list(jan,feb,march,april)

  2. #2

    The Easy Solution

    Evening There.

    The easiest way to do this is to add a second Field to your table that holds the data for your month number. Your table would look something like this...

    MonthID MonthName
    1 January
    3 March
    12 December
    2 February
    10 October
    9 September
    5 May

    From there, you can run the following statement and it will provide the record in the order of the Month's numerical value, ascending from 1 to 12.

    "SELECT MonthName FROM Months ORDER BY MonthID ASC;"

    Good Luck.
    Scott

  3. #3
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    thanks i already have answer

    ORDER BY
    CASE MONTH_FIELD
    WHEN 'JANUARY' THEN '1'
    WHEN 'FEBRUARY' THEN '2'
    ...
    ...
    ...
    END

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Another way

    [vba]

    ORDER BY Month(DateValue(""01-"" & Month_Field))
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •