record sorting options

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

  1. #1

    Default record sorting options

    Im working on a small sales lead tracking application.

    One of the features requested by my client is to sort records by status.
    There are 6 different status values to which Ive assigned numbers - 1 thru
    6.

    I can sort simply by ascending or descending but is it possible to sort in
    different ways?

    For instance, if the user wants to display all the status 3 records first,
    followed buy status 1, status 2, etc. Would look like this:
    Status 3
    Status 1
    Status 2
    Status 4
    Status 5
    Status 6

    Can this be done?

    Thanks


    Targa Guest

  2. Similar Questions and Discussions

    1. How can i retrieve record ONLY From 300 - 400 in amillion Record Table?
      HI all Thanks for your time.. I have a question here.. How can i retrieve record ONLY From XXX - XXX in a million Record Table? eg. I have a...
    2. Find record w/ conditions met in the same child record
      I'll use 2 files to demonstrate my question. The first file is Animal. It has 4 fields. Id (serial number) ZooId (number) Name (text) Food...
    3. value list with unique options by current record
      How can I make a value list to which I can add not only to the whole list by checking the possibility to show "edit", but also add options stored...
    4. Stop adding record in subform after record count = 1
      Can someone help in in what to put after the THEN statment to allow one entry if the Record count is =>1 in the Before insert or should I set the...
    5. Options and creating a macro for options
      I have a database that i use for work and have set up to have 10-12 option groups on one page. Normally I would "hit" the "Pass" option (the other...
  3. #2

    Default Re: record sorting options

    Use a UNION query. Something like:

    SELECT
    Field1, Field2, 1
    FROM
    myTable
    WHERE
    Status = 3
    UNION
    SELECT
    Field1, Field2, 2
    FROM
    myTable
    WHERE
    Status = 1
    ORDER BY
    3 -- orders by the appended number

    Cheers
    Ken



    "Targa" <targa1SPAMSUCKS@alltel.net> wrote in message
    news:uXUTuLugDHA.524@tk2msftngp13.phx.gbl...
    : Im working on a small sales lead tracking application.
    :
    : One of the features requested by my client is to sort records by status.
    : There are 6 different status values to which Ive assigned numbers - 1 thru
    : 6.
    :
    : I can sort simply by ascending or descending but is it possible to sort in
    : different ways?
    :
    : For instance, if the user wants to display all the status 3 records first,
    : followed buy status 1, status 2, etc. Would look like this:
    : Status 3
    : Status 1
    : Status 2
    : Status 4
    : Status 5
    : Status 6
    :
    : Can this be done?
    :
    : Thanks
    :
    :


    Ken Schaefer Guest

  4. #3

    Default Re: record sorting options

    I think this will work.

    SELECT TABLE1.RecordTitle, TABLE1.Status FROM
    (SELECT S.ID, CASE S.Status WHEN 3 THEN 0 ELSE 1 END AS ShowTop FROM
    TABLE1 S) AS ST
    INNER JOIN TABLE1 ON ST.ID=TABLE1.ID
    ORDER BY ST.ShowTop, TABLE1.Status

    Ray at home



    "Targa" <targa1SPAMSUCKS@alltel.net> wrote in message
    news:uXUTuLugDHA.524@tk2msftngp13.phx.gbl...
    > Im working on a small sales lead tracking application.
    >
    > One of the features requested by my client is to sort records by status.
    > There are 6 different status values to which Ive assigned numbers - 1 thru
    > 6.
    >
    > I can sort simply by ascending or descending but is it possible to sort in
    > different ways?
    >
    > For instance, if the user wants to display all the status 3 records first,
    > followed buy status 1, status 2, etc. Would look like this:
    > Status 3
    > Status 1
    > Status 2
    > Status 4
    > Status 5
    > Status 6
    >
    > Can this be done?
    >
    > Thanks
    >
    >

    Ray at Guest

  5. #4

    Default Re: record sorting options

    I think you meant this, but correct me if I'm wrong.

    SELECT Field1, Field2, 1 FROM myTable WHERE Status=3 UNION SELECT Field1,
    Field2, 2 WHERE STATUS <> 3 ORDER BY 3, Status

    Ray at home

    "Ken Schaefer" <kenREMOVE@THISadOpenStatic.com> wrote in message
    news:ejRYR1wgDHA.1748@TK2MSFTNGP10.phx.gbl...
    > Use a UNION query. Something like:
    >
    > SELECT
    > Field1, Field2, 1
    > FROM
    > myTable
    > WHERE
    > Status = 3
    > UNION
    > SELECT
    > Field1, Field2, 2
    > FROM
    > myTable
    > WHERE
    > Status = 1
    > ORDER BY
    > 3 -- orders by the appended number
    >
    > Cheers
    > Ken
    >
    >
    >
    > "Targa" <targa1SPAMSUCKS@alltel.net> wrote in message
    > news:uXUTuLugDHA.524@tk2msftngp13.phx.gbl...
    > : Im working on a small sales lead tracking application.
    > :
    > : One of the features requested by my client is to sort records by status.
    > : There are 6 different status values to which Ive assigned numbers - 1
    thru
    > : 6.
    > :
    > : I can sort simply by ascending or descending but is it possible to sort
    in
    > : different ways?
    > :
    > : For instance, if the user wants to display all the status 3 records
    first,
    > : followed buy status 1, status 2, etc. Would look like this:
    > : Status 3
    > : Status 1
    > : Status 2
    > : Status 4
    > : Status 5
    > : Status 6
    > :
    > : Can this be done?
    > :
    > : Thanks
    > :
    > :
    >
    >

    Ray at Guest

  6. #5

    Default Re: record sorting options

    No, I meant what I wrote. :-)

    I was just trying to give a simple example of putting records where Status =
    3 ahead of records where Status = 1. The OP could then append another query
    to put Status = 2 records after the Status = 1 records (and so forth for all
    the specified statii, or is that statuses?).

    The addition of the ORDER BY ... Status doesn't add anything to the query,
    since you are already ordering the records by an arbitrary value (in the 3
    column) based on the value of the status field of that record. You could
    order by other fields though.

    So:

    SELECT
    Field1
    , Field2
    , 1
    FROM
    myTable
    WHERE
    Status = 3
    UNION
    SELECT
    Field1
    , Field2
    , 2
    FROM
    myTable
    WHERE
    Status = 1
    UNION
    SELECT
    Field1
    , Field2
    , 3
    FROM
    myTable
    WHERE
    Status = 2
    ORDER BY
    3
    , Field1
    , Field2


    Cheers
    Ken

    "Ray at <%=sLocation%>" <myfirstname at lane 34 . komm> wrote in message
    news:uw6$OQxgDHA.2408@TK2MSFTNGP09.phx.gbl...
    : I think you meant this, but correct me if I'm wrong.
    :
    : SELECT Field1, Field2, 1 FROM myTable WHERE Status=3 UNION SELECT Field1,
    : Field2, 2 WHERE STATUS <> 3 ORDER BY 3, Status
    :
    : Ray at home
    :
    : "Ken Schaefer" <kenREMOVE@THISadOpenStatic.com> wrote in message
    : news:ejRYR1wgDHA.1748@TK2MSFTNGP10.phx.gbl...
    : > Use a UNION query. Something like:
    : >
    : > SELECT
    : > Field1, Field2, 1
    : > FROM
    : > myTable
    : > WHERE
    : > Status = 3
    : > UNION
    : > SELECT
    : > Field1, Field2, 2
    : > FROM
    : > myTable
    : > WHERE
    : > Status = 1
    : > ORDER BY
    : > 3 -- orders by the appended number
    : >
    : > Cheers
    : > Ken
    : >
    : >
    : >
    : > "Targa" <targa1SPAMSUCKS@alltel.net> wrote in message
    : > news:uXUTuLugDHA.524@tk2msftngp13.phx.gbl...
    : > : Im working on a small sales lead tracking application.
    : > :
    : > : One of the features requested by my client is to sort records by
    status.
    : > : There are 6 different status values to which Ive assigned numbers - 1
    : thru
    : > : 6.
    : > :
    : > : I can sort simply by ascending or descending but is it possible to
    sort
    : in
    : > : different ways?
    : > :
    : > : For instance, if the user wants to display all the status 3 records
    : first,
    : > : followed buy status 1, status 2, etc. Would look like this:
    : > : Status 3
    : > : Status 1
    : > : Status 2
    : > : Status 4
    : > : Status 5
    : > : Status 6
    : > :
    : > : Can this be done?
    : > :
    : > : Thanks
    : > :
    : > :
    : >
    : >
    :
    :


    Ken Schaefer Guest

  7. #6

    Default Re: record sorting options

    Perhaps add a SortNum field to the Status table and sort on that instead of the
    Status field itself.

    Bullschmidt 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