I have made a query that does a cross-tab of data. The date data is normal like 02/04/2004, 03/04/2004 etc.
I am using Month Name to group the dates by Month name.
My problem is the query result sorts the month names in alphabetical order, not month order.
I am using the query to generate a graph and the months are not in order.
Is there a way to sort the months by month order not alphabetical order.
Thanks
GoongI usually will have to use the month name for display and the month number for sorting. I'd have to see the query to advise how you might accomplish that.
Terri|||Hi Terri
SELECT { fn MONTHNAME(EnteredDate) } AS Month,
COUNT(CASE WHEN pesttype = 'rats' THEN id ELSE NULL END) AS rats,
COUNT(CASE WHEN pesttype = 'mice' THEN id ELSE NULL END) AS Mice,
COUNT(CASE WHEN pesttype = 'pigeons' THEN id ELSE NULL END) AS Pigeons,
COUNT(CASE WHEN pesttype = 'birds' THEN id ELSE NULL END) AS birds
FROM pestsighting
GROUP BY { fn MONTHNAME(EnteredDate) }
This query is used to present data to build a Stacked Bar Chart.
Thanks
Goong|||I would use this:
SELECT DATENAME(month,EnteredDate) AS Month,
MONTH(EnteredDate) AS MonthNumber,
COUNT(CASE WHEN pesttype = 'rats' THEN id ELSE NULL END) AS rats,
COUNT(CASE WHEN pesttype = 'mice' THEN id ELSE NULL END) AS Mice,
COUNT(CASE WHEN pesttype = 'pigeons' THEN id ELSE NULL END) AS Pigeons,
COUNT(CASE WHEN pesttype = 'birds' THEN id ELSE NULL END) AS birds
FROM pestsighting
GROUP BY DATENAME(month,EnteredDate), MONTH(EnteredDate)
ORDER BY 2
Terri
PS, sounds like a fun project ;-)|||Thanks Terri,
Works Great
Goong
No comments:
Post a Comment