Subject | RE: [firebird-support] Too many Contexts of Relation/Procedure/Views. Maximum allowed is 255. |
---|---|
Author | Leyne, Sean |
Post date | 2008-10-07T21:55:59Z |
Fabio,
Given that you can run Firebird v2.+, I would suggest a different
approach
{turn the problem 90 degrees}
Sean
SELECT
IM.tag_codice codice_01,
tag.descrizione descrizione_01,
...
CASE WHEN (IM.IMESE = 01) THEN IM.ISum ELSE 0 END as Importo_01,
CASE WHEN (IM.IMESE = 02) THEN IM.ISum ELSE 0 END as Importo_02,
CASE WHEN (IM.IMESE = 03) THEN IM.ISum ELSE 0 END as Importo_03,
CASE WHEN (IM.IMESE = 04) THEN IM.ISum ELSE 0 END as Importo_04,
...
0 importo_raffronto_01,
0 importo_raffronto_02,
0 importo_raffronto_03,
0 importo_raffronto_04,
...
FROM (
Select
stv.tag_codice,
stv.cli_codice,
stv.art_codice,
stv.mese as IMese,
sum(importo) as ISum
from stv
where
stv.anno = 2007
GROUP BY
1, 2, 3, 4
) as IM
inner join tag on tag.codice = IM.tag_codice
inner join cli on cli.codice = IM.cli_codice
inner join tsc on tsc.codice = cli.tsc_codice
inner join tzo on tzo.codice = cli.tzo_codice
inner join tar on tar.codice = cli.tar_codice
inner join tcg on tcg.codice = cli.tcg_codice
inner join art on art.codice = IM.art_codice
inner join tsa on tsa.codice = art.tsa_codice
inner join tcm on tcm.codice = art.tcm_codice
inner join tgm on tgm.codice = art.tgm_codice
order by
1, ...
Note: No WHERE clause is required since the Abstract Table IM will only
have entries where at least 1 entry appears, and the original SQL was
simply ensuring that only entries with non-zero Import_0x values were
returned.
Given that you can run Firebird v2.+, I would suggest a different
approach
{turn the problem 90 degrees}
Sean
SELECT
IM.tag_codice codice_01,
tag.descrizione descrizione_01,
...
CASE WHEN (IM.IMESE = 01) THEN IM.ISum ELSE 0 END as Importo_01,
CASE WHEN (IM.IMESE = 02) THEN IM.ISum ELSE 0 END as Importo_02,
CASE WHEN (IM.IMESE = 03) THEN IM.ISum ELSE 0 END as Importo_03,
CASE WHEN (IM.IMESE = 04) THEN IM.ISum ELSE 0 END as Importo_04,
...
0 importo_raffronto_01,
0 importo_raffronto_02,
0 importo_raffronto_03,
0 importo_raffronto_04,
...
FROM (
Select
stv.tag_codice,
stv.cli_codice,
stv.art_codice,
stv.mese as IMese,
sum(importo) as ISum
from stv
where
stv.anno = 2007
GROUP BY
1, 2, 3, 4
) as IM
inner join tag on tag.codice = IM.tag_codice
inner join cli on cli.codice = IM.cli_codice
inner join tsc on tsc.codice = cli.tsc_codice
inner join tzo on tzo.codice = cli.tzo_codice
inner join tar on tar.codice = cli.tar_codice
inner join tcg on tcg.codice = cli.tcg_codice
inner join art on art.codice = IM.art_codice
inner join tsa on tsa.codice = art.tsa_codice
inner join tcm on tcm.codice = art.tcm_codice
inner join tgm on tgm.codice = art.tgm_codice
order by
1, ...
Note: No WHERE clause is required since the Abstract Table IM will only
have entries where at least 1 entry appears, and the original SQL was
simply ensuring that only entries with non-zero Import_0x values were
returned.
> -----Original Message-----Relation/Procedure/Views.
> From: firebird-support@yahoogroups.com [mailto:firebird-
> support@yahoogroups.com] On Behalf Of Codebue Fabio - P-Soft
> Sent: Tuesday, October 07, 2008 4:26 PM
> To: firebird-support@yahoogroups.com
> Subject: [firebird-support] Too many Contexts of
> Maximum allowed is 255.Relation/Procedure/Views.
>
> I have this kind of sql:
>
> select distinct
> stv_01.tag_codice codice_01,
> tag.descrizione descrizione_01,
> coalesce((select sum(importo)
> from stv
> inner join cli on cli.codice = stv.cli_codice
> inner join art on art.codice = stv.art_codice
> where stv.anno = 2007 and stv.mese = 01 and
> stv.tag_codice = stv_01.tag_codice and
> stv.cli_codice = stv_01.cli_codice and
> stv.art_codice = stv_01.art_codice ), 0)
> importo_01,
> coalesce((select sum(importo)
> from stv
> inner join cli on cli.codice = stv.cli_codice
> inner join art on art.codice = stv.art_codice
> where stv.anno = 2007 and stv.mese = 02 and
> stv.tag_codice = stv_01.tag_codice and
> stv.cli_codice = stv_01.cli_codice and
> stv.art_codice = stv_01.art_codice), 0)
> importo_02,
> coalesce((select sum(importo)
> from stv
> inner join cli on cli.codice = stv.cli_codice
> inner join art on art.codice = stv.art_codice
> where stv.anno = 2007 and stv.mese = 03 and
> stv.tag_codice = stv_01.tag_codice and
> stv.cli_codice = stv_01.cli_codice and
> stv.art_codice = stv_01.art_codice), 0)
> importo_03,
> ...
>
>
> but I receive this error: Too many Contexts of
> Maximum allowed is 255
>
> probably I have to change my way to prepare sql... some ideas?
>
> this work on mysql, damn!!!!!
>
> fab10
> .-----------------------------.
>
>