Subject | SV: [firebird-support] How do you 0/null results to a GROUP BY query |
---|---|
Author | Svein Erling Tysvær |
Post date | 2012-10-29T10:11:49Z |
>Thanks! I will most likely go with the reference table(s) option, but IOne alternative that I don't think have been mentioned, Cornie, is EXECUTE BLOCK, which is simpler than a recursive CTE without requiring any extra table:
>will test both.
execute block returns (yearno integer, dayno integer, "SUM" integer)
as
declare variable d date;
declare variable dMax date;
begin
select MIN(DT), MAX(DT)
from CLIENT_INVOICES
into :d, :dMax; /*or use fixed FROM and TO dates*/
while (d <= dMax) do
begin
yearno = EXTRACT(YEAR from d);
dayno = EXTRACT(YEARDAY from d);
select coalesce(sum(DUE), 0)
from CLIENT_INVOICES
where DT = :d
into :"SUM";
suspend;
d=d+1;
end
end;
This works on recent Firebird versions (though I would recommend using a different name than SUM).
HTH,
Set