Re: Help with missing data in query
- From: Hugo Kornelis <hugo@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 16 Aug 2007 22:29:51 +0200
On Wed, 15 Aug 2007 17:02:04 -0700, SLIMSHIM wrote:
i"m including my final code it has one bug i can't get the sort order
straight
i.e. jan feb mar .......Total
it comes in alphabeticaly
Hi slimshim,
That's because you asked it to order on the month name column :-)
Change the last par tof the query to
GROUP BY m.MonthName WITH ROLLUP
ORDER BY MIN(m.MonthId)
I was first about to suggest to include MonthId in the GROUP BY, but I'm
not sure if the WITH ROLLUP option likes that. The workaround I chose is
to use an aggregate function for the ORDER BY.
If that doesn't work (you didn't follow the instructions I linked to
that would have enabled me to test before posting), then change the end
to
GROUP BY m.MonthID WITH ROLLUP
ORDER BY m.MonthID
and change the first line to read
SELECT MAX(COALESCE(m.MonthName, 'Total')) AS MONTH,
--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
.
- Follow-Ups:
- Re: Help with missing data in query
- From: SLIMSHIM
- Re: Help with missing data in query
- References:
- Re: Help with missing data in query
- From: Hugo Kornelis
- Re: Help with missing data in query
- From: SLIMSHIM
- Re: Help with missing data in query
- Prev by Date: Re: Help with missing data in query
- Next by Date: Re: Help with missing data in query
- Previous by thread: Re: Help with missing data in query
- Next by thread: Re: Help with missing data in query
- Index(es):
Relevant Pages
|
|