Subject | Re: How to arrange Year wise and then Month Wise |
---|---|
Author | mspencewasunavailable |
Post date | 2007-04-08T01:22:51Z |
--- In firebird-support@yahoogroups.com, "Muthu Annamalai"
<pearlamerica@...> wrote:
ORDER BY (CASE WHEN PERIOD >= 10 THEN PERIOD - 12 ELSE PERIOD END)
should work if you always want to start with October (because, for
example, that's the beginning of your fiscal year).
More generally, if you just want to get the next twelve months and
have an arbitrary start date, you could do this:
ORDER BY EXTRACT(YEAR FROM RECEIPTDATE) * 100 + EXTRACT(MONTH FROM
RECEIPTDATE)
Michael D. Spence
Mockingbird Data Systems, Inc.
<pearlamerica@...> wrote:
>Haven't tried either of these, but:
> I need help with arranging months in my stored procedure. See my SP
>
> FOR SELECT FIRST 12 EXTRACT(MONTH FROM RECEIPTDATE),COUNT(*),SUM
> (AMOUNT)
> FROM RECEIPT
> GROUP BY 1
> INTO :PERIOD,:RECEIPTS,:SALES
> DO SUSPEND;
>
> The stored procedure results are like this
>
> PERIOD
> 1
> 2
> 8
> 9
> 10
> 11
> 12
>
> I need to sort year wise first and then month as follows
>
> PERIOD
>
> 10
> 11
> 12
> 1
> 2
> 8
> 9
>
> Any help is highly appreciated
>
> Thanks,
>
> Muthu
>
ORDER BY (CASE WHEN PERIOD >= 10 THEN PERIOD - 12 ELSE PERIOD END)
should work if you always want to start with October (because, for
example, that's the beginning of your fiscal year).
More generally, if you just want to get the next twelve months and
have an arbitrary start date, you could do this:
ORDER BY EXTRACT(YEAR FROM RECEIPTDATE) * 100 + EXTRACT(MONTH FROM
RECEIPTDATE)
Michael D. Spence
Mockingbird Data Systems, Inc.