Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!
  1.   Become a Supporter    ::   Make a Contribution   
    Target (Recurring Monthly): $200 :: Achieved: $98

SQL sorting problem

Discussion in 'Information Technology' started by Adam@nospam.com, Jul 28, 2006.

  1. Adam@nospam.com

    Adam@nospam.com
    Expand Collapse
    Guest

    Hi All,

    I've finally managed to create a great crosstab query from a union
    query, but I want to sort a field in there in a custom way

    I have records under the 'Category' field called "I/C Presented","I/C
    Answered","PCA 20", "PCA 40".

    Now I want to sort the records in the way I've written them above,
    however if I choose to sort the records by Category in Ascending order
    "I/C Answered" appears at the top.

    Below is a copy of the SQL used in my crosstab query:

    ----------------
    TRANSFORM Max(qryUnionTest.Measurement) AS MaxOfMeasurement
    SELECT qryUnionTest.Teams, qryUnionTest.Category,
    Max(qryUnionTest.Measurement) AS [Total Of Measurement]
    FROM qryUnionTest
    GROUP BY qryUnionTest.Teams, qryUnionTest.Category
    ORDER BY qryUnionTest.Teams, qryUnionTest.Category
    PIVOT Format([MeasurementDate],"mmm") In
    ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
    ----------------

    Now under ORDER BY can I add:

    ORDER By qryUnionTest.Category In ("I/C Presented","I/C Answered","PCA
    20", "PCA 40") ?

    Many Thanks

    Adam
     
  2. Loading...

    Similar Threads Forum Date
    Microsoft Brings 64-Bit Perks in SQL Server 2000 Service Pack (Ziff Davis) Interfaith Dialogues May 7, 2005

  3. John Vinson

    John Vinson
    Expand Collapse
    Guest

    On 13 Jun 2006 09:32:43 -0700, "Adam@nospam.com"
    <adamevans81@gmail.com> wrote:

    >Now under ORDER BY can I add:
    >
    >ORDER By qryUnionTest.Category In ("I/C Presented","I/C Answered","PCA
    >20", "PCA 40") ?


    No; but you can use

    ORDER BY Switch([Category] = "I/C Presented", 1,
    [Category] = "I/C Answered", 2,
    [Category] = "PCA 20", 3,
    [Category] = "PCA 40, 4,
    True, 5)


    John W. Vinson[MVP]
     
  4. Adam@nospam.com

    Adam@nospam.com
    Expand Collapse
    Guest

    Brilliant, thank you.

    John Vinson wrote:

    > On 13 Jun 2006 09:32:43 -0700, "Adam@nospam.com"
    > <adamevans81@gmail.com> wrote:
    >
    > >Now under ORDER BY can I add:
    > >
    > >ORDER By qryUnionTest.Category In ("I/C Presented","I/C Answered","PCA
    > >20", "PCA 40") ?

    >
    > No; but you can use
    >
    > ORDER BY Switch([Category] = "I/C Presented", 1,
    > [Category] = "I/C Answered", 2,
    > [Category] = "PCA 20", 3,
    > [Category] = "PCA 40, 4,
    > True, 5)
    >
    >
    > John W. Vinson[MVP]
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page