Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Re: sorting queries

    You will need to create a sorting table with two columns: Category and Rank.
    Enter your categories into the table and enter the apropriate rank numbers.
    Then join Items to this new table using the Category columns and order by
    the Rank column.

    Bob Barrows

    Paul Sorrell wrote:
    > This is how I currently sort my query..........
    >
    > SELECT * FROM Items WHERE Availability = True ORDER By Category
    > DESC, Price DESC
    >
    > These are my categories.........
    >
    > SideBySide
    > Pair
    > Hammergun
    > UnderOver
    > DoubleRifle
    > Combination
    > Collectible
    > Auto
    > Rifle
    > Single
    > Airgun
    >
    > My question is, can I sort the categories in any way other than
    > ascending or descending?
    > I want to order them as above.
    >
    > Thanks in advance
    > Paul S

    Bob Barrows Guest

  2. Similar Questions and Discussions

    1. Sorting array vs sorting paginated array
      ....pulling in a long list of photos in a gallery, and I have a sort function working within the pages of data fine. I need to bring it back out of...
    2. Queries
      hi all, i am using the tutorial: Creating Dynamic Playlist and able to play it correctly, when i open the swf file and i observe that there is 6...
    3. Queries of Queries
      Hi, I am trying to combine two queries. The first is a basic query of a table in the database. <CFQUERY NAME="getStores"...
    4. Queries Of Queries Single Quote Problem
      When using queries of queries I'm having the following issue. Select Company_ID From qry_MyQuery Where Company_NM = 'MyString''s' <----...
    5. ASP.net Queries
      Hi Please suggest the solutions for the following questions in asp.net. 1) Is there any Mask edit control in asp.net?. If not possible can...
  3. #2

    Default Re: sorting queries

    There is no order to your categories, so how could a computer sort them like
    that? If you gave me that list on a piece of paper and asked me to sort
    them, I can guarantee that I would never have come up with that order.

    Anyway, enough of my snotty comments.

    I assume that your Categories are in a separate table, add a field for the
    order that the category should be sorted by.

    tblCategories
    CategoryID int
    Title varchar(50)
    SortOrder int

    Example data

    CategoryID Title SortOrder
    1 Pair 2
    2 SideBySide 1
    3 Hammergun 3

    "Paul Sorrell" <egguns@eggunsNOSPAM.demon.co.uk> wrote in message
    news:bfmrlo$47k$1$8300dec7@news.demon.co.uk...
    > This is how I currently sort my query..........
    >
    > SELECT * FROM Items WHERE Availability = True ORDER By Category DESC,
    > Price DESC
    >
    > These are my categories.........
    >
    > SideBySide
    > Pair
    > Hammergun
    > UnderOver
    > DoubleRifle
    > Combination
    > Collectible
    > Auto
    > Rifle
    > Single
    > Airgun
    >
    > My question is, can I sort the categories in any way other than ascending
    or
    > descending?
    > I want to order them as above.
    >
    > Thanks in advance
    > Paul S
    >
    >

    Tom B Guest

  4. #3

    Default Re: sorting queries

    You have hit the nail on the head, I do not have a separate table for
    categories.
    I understand the concept but need a quick and easy fix for what alreadt
    exists.

    Is there no way I can call one category after another without a separate
    table.

    Something like
    select * from items where category = sidebyside then pair then hammergun
    etc.....
    --

    Thank you,
    Paul Sorrell
    [url]http://www.egguns.demon.co.uk[/url]


    "Tom B" <shuckle@hotmail.com> wrote in message
    news:udG3ZzVUDHA.1712@TK2MSFTNGP11.phx.gbl...
    > There is no order to your categories, so how could a computer sort them
    like
    > that? If you gave me that list on a piece of paper and asked me to sort
    > them, I can guarantee that I would never have come up with that order.
    >
    > Anyway, enough of my snotty comments.
    >
    > I assume that your Categories are in a separate table, add a field for the
    > order that the category should be sorted by.
    >
    > tblCategories
    > CategoryID int
    > Title varchar(50)
    > SortOrder int
    >
    > Example data
    >
    > CategoryID Title SortOrder
    > 1 Pair 2
    > 2 SideBySide 1
    > 3 Hammergun 3
    >
    > "Paul Sorrell" <egguns@eggunsNOSPAM.demon.co.uk> wrote in message
    > news:bfmrlo$47k$1$8300dec7@news.demon.co.uk...
    > > This is how I currently sort my query..........
    > >
    > > SELECT * FROM Items WHERE Availability = True ORDER By Category DESC,
    > > Price DESC
    > >
    > > These are my categories.........
    > >
    > > SideBySide
    > > Pair
    > > Hammergun
    > > UnderOver
    > > DoubleRifle
    > > Combination
    > > Collectible
    > > Auto
    > > Rifle
    > > Single
    > > Airgun
    > >
    > > My question is, can I sort the categories in any way other than
    ascending
    > or
    > > descending?
    > > I want to order them as above.
    > >
    > > Thanks in advance
    > > Paul S
    > >
    > >
    >
    >


    Paul Sorrell Guest

  5. #4

    Default Re: sorting queries

    What DBMS?

    --
    Mark Schupp
    --
    Head of Development
    Integrity eLearning
    Online Learning Solutions Provider
    [email]mschupp@ielearning.com[/email]
    [url]http://www.ielearning.com[/url]
    714.637.9480 x17


    "Paul Sorrell" <egguns@eggunsNOSPAM.demon.co.uk> wrote in message
    news:bfn1cm$dju$1$8300dec7@news.demon.co.uk...
    > You have hit the nail on the head, I do not have a separate table for
    > categories.
    > I understand the concept but need a quick and easy fix for what alreadt
    > exists.
    >
    > Is there no way I can call one category after another without a separate
    > table.
    >
    > Something like
    > select * from items where category = sidebyside then pair then hammergun
    > etc.....
    > --
    >
    > Thank you,
    > Paul Sorrell
    > [url]http://www.egguns.demon.co.uk[/url]
    >
    >
    > "Tom B" <shuckle@hotmail.com> wrote in message
    > news:udG3ZzVUDHA.1712@TK2MSFTNGP11.phx.gbl...
    > > There is no order to your categories, so how could a computer sort them
    > like
    > > that? If you gave me that list on a piece of paper and asked me to sort
    > > them, I can guarantee that I would never have come up with that order.
    > >
    > > Anyway, enough of my snotty comments.
    > >
    > > I assume that your Categories are in a separate table, add a field for
    the
    > > order that the category should be sorted by.
    > >
    > > tblCategories
    > > CategoryID int
    > > Title varchar(50)
    > > SortOrder int
    > >
    > > Example data
    > >
    > > CategoryID Title SortOrder
    > > 1 Pair 2
    > > 2 SideBySide 1
    > > 3 Hammergun 3
    > >
    > > "Paul Sorrell" <egguns@eggunsNOSPAM.demon.co.uk> wrote in message
    > > news:bfmrlo$47k$1$8300dec7@news.demon.co.uk...
    > > > This is how I currently sort my query..........
    > > >
    > > > SELECT * FROM Items WHERE Availability = True ORDER By Category
    DESC,
    > > > Price DESC
    > > >
    > > > These are my categories.........
    > > >
    > > > SideBySide
    > > > Pair
    > > > Hammergun
    > > > UnderOver
    > > > DoubleRifle
    > > > Combination
    > > > Collectible
    > > > Auto
    > > > Rifle
    > > > Single
    > > > Airgun
    > > >
    > > > My question is, can I sort the categories in any way other than
    > ascending
    > > or
    > > > descending?
    > > > I want to order them as above.
    > > >
    > > > Thanks in advance
    > > > Paul S
    > > >
    > > >
    > >
    > >
    >
    >
    >

    Mark Schupp Guest

  6. #5

    Default Re: sorting queries

    "Paul Sorrell" <egguns@eggunsNOSPAM.demon.co.uk> wrote in message
    news:bfn1cm$dju$1$8300dec7@news.demon.co.uk...
    > You have hit the nail on the head, I do not have a separate table for
    > categories.
    > I understand the concept but need a quick and easy fix for what
    alreadt
    > exists.
    >
    > Is there no way I can call one category after another without a
    separate
    > table.
    >
    > Something like
    > select * from items where category = sidebyside then pair then
    hammergun
    > etc.....
    > --
    >
    > Thank you,
    > Paul Sorrell
    > [url]http://www.egguns.demon.co.uk[/url]
    Assuming RDMS = SQL Server
    SELECT
    *
    FROM
    Items
    ORDER BY
    CASE Category
    WHEN 'SideBySide' THEN 0
    WHEN 'Pair' THEN 1
    WHEN 'HammerGun' THEN 2
    WHEN 'UnderOver' THEN 3
    WHEN 'DoubleRifle' THEN 4
    WHEN 'Combination' THEN 5
    WHEN 'Collectible' THEN 6
    WHEN 'Auto' THEN 7
    WHEN 'Rifle' THEN 8
    WHEN 'Single' THEN 9
    WHEN 'Airgun' THEN 10
    END


    Chris Hohmann Guest

  7. #6

    Default Re: sorting queries

    Careful, I think he has guns.

    "Bob Barrows" <reb_01501@yahoo.com> wrote in message
    news:u%23EZg8XUDHA.2460@TK2MSFTNGP10.phx.gbl...
    > Quick and easy?!?!?
    > Don't do things quick and easy. Do them right!!
    >
    > Tell me: what is so slow and hard about creating a 2-column table with,
    > what, 10 rows of data? If that takes you any longer than 10 minutes you
    > should be really ashamed of yourself! Add another 30 seconds to add a join
    > statement to your query, and you have a solution in less than 11 minutes!
    > This isn't quick and easy???
    >
    > Why is this the right way to do it? Why not use the clever solution that
    > Chris provided?
    > 1. Performance - while Chris's solution will work, it won't allow any
    > indexes to be used to sort your data, leading to poor query performance
    > 2. Re-use - is this the only query that will need to use this sort order?
    > Are you sure? Do you want to reproduce that CASE statement every time you
    > need this sort order? And what about if you need to modify that sort
    order?
    > Are you going to remember every place you used that CASE statement? Is
    using
    > a separate ranking table starting to seem less slow and hard?
    >
    > Bob Barrows
    >
    > Paul Sorrell wrote:
    > > You have hit the nail on the head, I do not have a separate table for
    > > categories.
    > > I understand the concept but need a quick and easy fix for what
    > > alreadt exists.
    > >
    > > Is there no way I can call one category after another without a
    > > separate table.
    > >
    > > Something like
    > > select * from items where category = sidebyside then pair then
    > > hammergun etc.....
    > >
    > > "Tom B" <shuckle@hotmail.com> wrote in message
    > > news:udG3ZzVUDHA.1712@TK2MSFTNGP11.phx.gbl...
    > >> There is no order to your categories, so how could a computer sort
    > >> them like that? If you gave me that list on a piece of paper and
    > >> asked me to sort them, I can guarantee that I would never have come
    > >> up with that order.
    > >>
    > >> Anyway, enough of my snotty comments.
    > >>
    > >> I assume that your Categories are in a separate table, add a field
    > >> for the order that the category should be sorted by.
    > >>
    > >> tblCategories
    > >> CategoryID int
    > >> Title varchar(50)
    > >> SortOrder int
    > >>
    > >> Example data
    > >>
    > >> CategoryID Title SortOrder
    > >> 1 Pair 2
    > >> 2 SideBySide 1
    > >> 3 Hammergun 3
    > >>
    > >> "Paul Sorrell" <egguns@eggunsNOSPAM.demon.co.uk> wrote in message
    > >> news:bfmrlo$47k$1$8300dec7@news.demon.co.uk...
    > >>> This is how I currently sort my query..........
    > >>>
    > >>> SELECT * FROM Items WHERE Availability = True ORDER By Category
    > >>> DESC, Price DESC
    > >>>
    > >>> These are my categories.........
    > >>>
    > >>> SideBySide
    > >>> Pair
    > >>> Hammergun
    > >>> UnderOver
    > >>> DoubleRifle
    > >>> Combination
    > >>> Collectible
    > >>> Auto
    > >>> Rifle
    > >>> Single
    > >>> Airgun
    > >>>
    > >>> My question is, can I sort the categories in any way other than
    > >>> ascending or descending?
    > >>> I want to order them as above.
    > >>>
    > >>> Thanks in advance
    > >>> Paul S
    >
    >
    >

    Tom B Guest

  8. #7

    Default Re: sorting queries

    Bob Barrows wrote:
    <snip>

    I want to apologize for the tone of this reply (I stand by its content). I
    regret any unintended slight to Chris who was merely attempting to answer
    the question given. I will say again that his solution was, indeed, clever.

    Bob


    Bob Barrows Guest

  9. #8

    Default Re: sorting queries

    OK, now I'm confused. When I first saw Chris' reply I
    thought to myself, that won't work, so I tried it and it
    does (as you all already know).

    However, I'm stumped as to why. The ORDER BY Clause (as I
    understand it) takes column names as parameters:
    I.E. ORDER BY LastName
    Or, it can use the position of the column in the SELECT
    statement:
    I.E. SELECT Lastname, Firstname FROM MYTable ORDER BY 1

    Chris' statement doesn't seem to follow either of those
    rules.

    Can one of you SQL experts explain this to me?

    SELECT
    *
    FROM
    Items
    ORDER BY
    CASE Category
    WHEN 'SideBySide' THEN 0
    WHEN 'Pair' THEN 1
    WHEN 'HammerGun' THEN 2
    WHEN 'UnderOver' THEN 3
    WHEN 'DoubleRifle' THEN 4
    WHEN 'Combination' THEN 5
    WHEN 'Collectible' THEN 6
    WHEN 'Auto' THEN 7
    WHEN 'Rifle' THEN 8
    WHEN 'Single' THEN 9
    WHEN 'Airgun' THEN 10
    END

    John Beschler Guest

  10. #9

    Default Re: sorting queries

    Thanks Bob. That one really blew my mind!

    >-----Original Message-----
    >A virtual column is created by the CASE statement. The
    content of that
    >column is determined by the output of the CASE statement.
    It's as if you put
    >the CASE statement into your SELECT clause like this:
    >
    >SELECT
    >*,
    >CASE Category
    >WHEN 'SideBySide' THEN 0
    >WHEN 'Pair' THEN 1
    >WHEN 'HammerGun' THEN 2
    >WHEN 'UnderOver' THEN 3
    >WHEN 'DoubleRifle' THEN 4
    >WHEN 'Combination' THEN 5
    >WHEN 'Collectible' THEN 6
    >WHEN 'Auto' THEN 7
    >WHEN 'Rifle' THEN 8
    >WHEN 'Single' THEN 9
    >WHEN 'Airgun' THEN 10
    >END As Rank
    >FROM
    >Items
    >ORDER BY Rank
    >
    >HTH,
    >Bob Barrows
    >
    >
    >John Beschler wrote:
    >> OK, now I'm confused. When I first saw Chris' reply I
    >> thought to myself, that won't work, so I tried it and it
    >> does (as you all already know).
    >>
    >> However, I'm stumped as to why. The ORDER BY Clause (as
    I
    >> understand it) takes column names as parameters:
    >> I.E. ORDER BY LastName
    >> Or, it can use the position of the column in the SELECT
    >> statement:
    >> I.E. SELECT Lastname, Firstname FROM MYTable ORDER BY 1
    >>
    >> Chris' statement doesn't seem to follow either of those
    >> rules.
    >>
    >> Can one of you SQL experts explain this to me?
    >>
    >> SELECT
    >> *
    >> FROM
    >> Items
    >> ORDER BY
    >> CASE Category
    >> WHEN 'SideBySide' THEN 0
    >> WHEN 'Pair' THEN 1
    >> WHEN 'HammerGun' THEN 2
    >> WHEN 'UnderOver' THEN 3
    >> WHEN 'DoubleRifle' THEN 4
    >> WHEN 'Combination' THEN 5
    >> WHEN 'Collectible' THEN 6
    >> WHEN 'Auto' THEN 7
    >> WHEN 'Rifle' THEN 8
    >> WHEN 'Single' THEN 9
    >> WHEN 'Airgun' THEN 10
    >> END
    >
    >
    >.
    >
    John Beschler Guest

  11. #10

    Default Re: sorting queries

    "Bob Barrows" <reb_01501@yahoo.com> wrote in message
    news:%23SD1PBeUDHA.2272@TK2MSFTNGP11.phx.gbl...
    > Bob Barrows wrote:
    > <snip>
    >
    > I want to apologize for the tone of this reply (I stand by its
    content). I
    > regret any unintended slight to Chris who was merely attempting to
    answer
    > the question given. I will say again that his solution was, indeed,
    clever.
    >
    > Bob
    >
    >
    No offense taken. In fact, I should have included a disclaimer that I
    was not advocating this method for general use. It was in response to "I
    understand the concept but need a quick and easy fix for what
    alreadt[sic] exists." The one thing I will add to your general (and
    better) solution is that Paul may want to a string instead of numbers
    for the rank column. A numeric column can bite you in the ass later on
    when you need to move a record in between the items ranked 1 and 2.

    HTH-
    Chris


    Chris Hohmann Guest

  12. #11

    Default Re: sorting queries

    That should read "Paul may want to USE a string..."


    Chris Hohmann Guest

  13. #12

    Default Re: sorting queries

    Chris Hohmann wrote:
    > That should read "Paul may want to USE a string..."
    Sorry, but that went right over my head ... :-)

    What should read "Paul may want to USE a string..."?

    Bob


    Bob Barrows Guest

  14. #13

    Default Re: sorting queries

    What is meant
    Assuming RDMS = SQL Server?
    Mine is an Access database, is this the reason why I cant make it work?

    Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

    [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in
    query expression 'CASE Category WHEN 'SideBySide' THEN 0 WHEN 'Pair' THEN 1
    WHEN 'HammerGun' THEN 2 WHEN 'UnderOver' THEN 3 WHEN 'DoubleRifle' THEN 4
    WHEN 'Combination' THEN 5 WHEN 'Collectible' THEN 6 WHEN 'Auto' THEN 7 WHEN
    'Rifle' THEN 8 WHEN 'Single' THEN 9 WHEN 'Airg'.

    /gunshop/StockListPrintOut.asp, line 31

    Here is my code.............

    <%Set AllItems = Connect.Execute(_
    "SELECT *
    CASE Category
    WHEN 'SideBySide' THEN 0
    WHEN 'Pair' THEN 1
    WHEN 'HammerGun' THEN 2
    WHEN 'UnderOver' THEN 3
    WHEN 'DoubleRifle' THEN 4
    WHEN 'Combination' THEN 5
    WHEN 'Collectible' THEN 6
    WHEN 'Auto' THEN 7
    WHEN 'Rifle' THEN 8
    WHEN 'Single' THEN 9
    WHEN 'Airgun' THEN 10
    END As Rank
    FROM
    Items
    ORDER BY Rank, Price DESC ")%>


    "Bob Barrows" <reb_01501@yahoo.com> wrote in message
    news:urBi2RfUDHA.1872@TK2MSFTNGP12.phx.gbl...
    > A virtual column is created by the CASE statement. The content of that
    > column is determined by the output of the CASE statement. It's as if you
    put
    > the CASE statement into your SELECT clause like this:
    >
    > SELECT
    > *,
    > CASE Category
    > WHEN 'SideBySide' THEN 0
    > WHEN 'Pair' THEN 1
    > WHEN 'HammerGun' THEN 2
    > WHEN 'UnderOver' THEN 3
    > WHEN 'DoubleRifle' THEN 4
    > WHEN 'Combination' THEN 5
    > WHEN 'Collectible' THEN 6
    > WHEN 'Auto' THEN 7
    > WHEN 'Rifle' THEN 8
    > WHEN 'Single' THEN 9
    > WHEN 'Airgun' THEN 10
    > END As Rank
    > FROM
    > Items
    > ORDER BY Rank
    >
    > HTH,
    > Bob Barrows
    >
    >
    > John Beschler wrote:
    > > OK, now I'm confused. When I first saw Chris' reply I
    > > thought to myself, that won't work, so I tried it and it
    > > does (as you all already know).
    > >
    > > However, I'm stumped as to why. The ORDER BY Clause (as I
    > > understand it) takes column names as parameters:
    > > I.E. ORDER BY LastName
    > > Or, it can use the position of the column in the SELECT
    > > statement:
    > > I.E. SELECT Lastname, Firstname FROM MYTable ORDER BY 1
    > >
    > > Chris' statement doesn't seem to follow either of those
    > > rules.
    > >
    > > Can one of you SQL experts explain this to me?
    > >
    > > SELECT
    > > *
    > > FROM
    > > Items
    > > ORDER BY
    > > CASE Category
    > > WHEN 'SideBySide' THEN 0
    > > WHEN 'Pair' THEN 1
    > > WHEN 'HammerGun' THEN 2
    > > WHEN 'UnderOver' THEN 3
    > > WHEN 'DoubleRifle' THEN 4
    > > WHEN 'Combination' THEN 5
    > > WHEN 'Collectible' THEN 6
    > > WHEN 'Auto' THEN 7
    > > WHEN 'Rifle' THEN 8
    > > WHEN 'Single' THEN 9
    > > WHEN 'Airgun' THEN 10
    > > END
    >
    >

    Paul Sorrell Guest

  15. #14

    Default Re: sorting queries

    Yes. Access does not have a CASE statement. Instead, you will need to use a
    whole bunch of nested Iif statements (not my idea of "quick and easy"
    <wink> ):

    ORDER BY IIF(Category = 'SideBySide',0,IIF(Category = Pair,1,IIF...))

    HTH,
    Bob Barrows

    Paul Sorrell wrote:
    > What is meant
    > Assuming RDMS = SQL Server?
    > Mine is an Access database, is this the reason why I cant make it
    > work?
    >
    > Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
    >
    > [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing
    > operator) in query expression 'CASE Category WHEN 'SideBySide' THEN 0
    > WHEN 'Pair' THEN 1 WHEN 'HammerGun' THEN 2 WHEN 'UnderOver' THEN 3
    > WHEN 'DoubleRifle' THEN 4 WHEN 'Combination' THEN 5 WHEN
    > 'Collectible' THEN 6 WHEN 'Auto' THEN 7 WHEN 'Rifle' THEN 8 WHEN
    > 'Single' THEN 9 WHEN 'Airg'.
    >
    > /gunshop/StockListPrintOut.asp, line 31
    >
    > Here is my code.............
    >
    > <%Set AllItems = Connect.Execute(_
    > "SELECT *
    > CASE Category
    > WHEN 'SideBySide' THEN 0
    > WHEN 'Pair' THEN 1
    > WHEN 'HammerGun' THEN 2
    > WHEN 'UnderOver' THEN 3
    > WHEN 'DoubleRifle' THEN 4
    > WHEN 'Combination' THEN 5
    > WHEN 'Collectible' THEN 6
    > WHEN 'Auto' THEN 7
    > WHEN 'Rifle' THEN 8
    > WHEN 'Single' THEN 9
    > WHEN 'Airgun' THEN 10
    > END As Rank
    > FROM
    > Items
    > ORDER BY Rank, Price DESC ")%>
    >
    >
    > "Bob Barrows" <reb_01501@yahoo.com> wrote in message
    > news:urBi2RfUDHA.1872@TK2MSFTNGP12.phx.gbl...
    >> A virtual column is created by the CASE statement. The content of
    >> that column is determined by the output of the CASE statement. It's
    >> as if you put the CASE statement into your SELECT clause like this:
    >>
    >> SELECT
    >> *,
    >> CASE Category
    >> WHEN 'SideBySide' THEN 0
    >> WHEN 'Pair' THEN 1
    >> WHEN 'HammerGun' THEN 2
    >> WHEN 'UnderOver' THEN 3
    >> WHEN 'DoubleRifle' THEN 4
    >> WHEN 'Combination' THEN 5
    >> WHEN 'Collectible' THEN 6
    >> WHEN 'Auto' THEN 7
    >> WHEN 'Rifle' THEN 8
    >> WHEN 'Single' THEN 9
    >> WHEN 'Airgun' THEN 10
    >> END As Rank
    >> FROM
    >> Items
    >> ORDER BY Rank
    >>
    >> HTH,
    >> Bob Barrows
    >>
    >>
    >> John Beschler wrote:
    >>> OK, now I'm confused. When I first saw Chris' reply I
    >>> thought to myself, that won't work, so I tried it and it
    >>> does (as you all already know).
    >>>
    >>> However, I'm stumped as to why. The ORDER BY Clause (as I
    >>> understand it) takes column names as parameters:
    >>> I.E. ORDER BY LastName
    >>> Or, it can use the position of the column in the SELECT
    >>> statement:
    >>> I.E. SELECT Lastname, Firstname FROM MYTable ORDER BY 1
    >>>
    >>> Chris' statement doesn't seem to follow either of those
    >>> rules.
    >>>
    >>> Can one of you SQL experts explain this to me?
    >>>
    >>> SELECT
    >>> *
    >>> FROM
    >>> Items
    >>> ORDER BY
    >>> CASE Category
    >>> WHEN 'SideBySide' THEN 0
    >>> WHEN 'Pair' THEN 1
    >>> WHEN 'HammerGun' THEN 2
    >>> WHEN 'UnderOver' THEN 3
    >>> WHEN 'DoubleRifle' THEN 4
    >>> WHEN 'Combination' THEN 5
    >>> WHEN 'Collectible' THEN 6
    >>> WHEN 'Auto' THEN 7
    >>> WHEN 'Rifle' THEN 8
    >>> WHEN 'Single' THEN 9
    >>> WHEN 'Airgun' THEN 10
    >>> END

    Bob Barrows Guest

  16. #15

    Default Re: sorting queries

    news:OBkPewgUDHA.1956@TK2MSFTNGP10.phx.gbl


    Chris Hohmann Guest

  17. #16

    Default Re: sorting queries

    Chris Hohmann wrote:
    > news:OBkPewgUDHA.1956@TK2MSFTNGP10.phx.gbl
    Ah - I wonder why I never got this message...

    As to your point, can use the old programmer's trick of initially numbering
    the ranks by 10: 10,20,30 ...

    I usually just renumber them when the number of rows is this small.

    Bob


    Bob Barrows Guest

  18. #17

    Default Re: sorting queries

    "Paul Sorrell" <egguns@eggunsNOSPAM.demon.co.uk> wrote in message
    news:bfpfq4$oi$1$830fa78d@news.demon.co.uk...
    > What is meant
    > Assuming RDMS = SQL Server?
    > Mine is an Access database, is this the reason why I cant make it
    work?

    Yes. When posting a database related question, it is often helpful to
    indicate what database and version you are using. For Access you will
    need to use IIF/SWITCH.

    SELECT
    ..
    ..
    ..
    ORDER BY
    SWITCH
    (
    Category="SideBySide",0
    Category="Pair",1
    ..
    ..
    ..
    )

    HTH
    -Chris


    Chris Hohmann Guest

  19. #18

    Default Re: sorting queries

    Aargh! I forgot about SWITCH! SWITCH will probably be easier than nested
    IIF's

    ORDER BY Switch(Category = 'SideBySide',0,Category = 'Pair',1,...)

    Bob Barrows

    Chris Hohmann wrote:
    > "Paul Sorrell" <egguns@eggunsNOSPAM.demon.co.uk> wrote in message
    > news:bfpfq4$oi$1$830fa78d@news.demon.co.uk...
    >> What is meant
    >> Assuming RDMS = SQL Server?
    >> Mine is an Access database, is this the reason why I cant make it
    >> work?
    >
    > Yes. When posting a database related question, it is often helpful to
    > indicate what database and version you are using. For Access you will
    > need to use IIF/SWITCH.
    >
    > SELECT
    > .
    > .
    > .
    > ORDER BY
    > SWITCH
    > (
    > Category="SideBySide",0
    > Category="Pair",1
    > .
    > .
    > .
    > )
    >
    > HTH
    > -Chris

    Bob Barrows Guest

  20. #19

    Default Re: sorting queries

    Hooray,
    Thanks all thats perfect.

    (anyone want to buy a gun?)
    paul.


    "Bob Barrows" <reb_01501@yahoo.com> wrote in message
    news:utocmbiUDHA.2284@TK2MSFTNGP09.phx.gbl...
    > Aargh! I forgot about SWITCH! SWITCH will probably be easier than nested
    > IIF's
    >
    > ORDER BY Switch(Category = 'SideBySide',0,Category = 'Pair',1,...)
    >
    > Bob Barrows
    >
    > Chris Hohmann wrote:
    > > "Paul Sorrell" <egguns@eggunsNOSPAM.demon.co.uk> wrote in message
    > > news:bfpfq4$oi$1$830fa78d@news.demon.co.uk...
    > >> What is meant
    > >> Assuming RDMS = SQL Server?
    > >> Mine is an Access database, is this the reason why I cant make it
    > >> work?
    > >
    > > Yes. When posting a database related question, it is often helpful to
    > > indicate what database and version you are using. For Access you will
    > > need to use IIF/SWITCH.
    > >
    > > SELECT
    > > .
    > > .
    > > .
    > > ORDER BY
    > > SWITCH
    > > (
    > > Category="SideBySide",0
    > > Category="Pair",1
    > > .
    > > .
    > > .
    > > )
    > >
    > > HTH
    > > -Chris
    >
    >

    Paul Sorrell Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139