Subject | [firebird-support] WITH RECURSIVE problem about enumerating depth |
---|---|
Author | Codebue Fabio - P-Soft |
Post date | 2009-02-02T16:22:08Z |
I need to make a recursive SQL like this. My goal is to explode a recursive
structure and mantain a depth dimensioni into field LIV without haveing a
real field into table.
WITH RECURSIVE
DiBa AS (
SELECT
P.ID AS ID, P.art_codice_padre AS ART_CODICE_PADRE,
P.SEQUENZA AS SEQUENZA, 1 AS LIVELLO,
P.art_codice_figlio AS ART_CODICE_FIGLIO,
P.DESCRIZIONE AS DESCRIZIONE,
P.DATA_INIZIO AS DATA_INIZIO, P.DATA_FINE AS DATA_FINE
FROM dsb_tmp P
WHERE P.utente = :utente AND P.art_codice_padre = :codice_padre
UNION ALL
SELECT
D.ID AS ID, D.art_codice_padre AS ART_CODICE_PADRE,
D.SEQUENZA AS SEQUENZA, (LIVELLO +1) AS LIVELLO,
D.art_codice_figlio AS ART_CODICE_FIGLIO,
D.DESCRIZIONE AS DESCRIZIONE,
D.DATA_INIZIO AS DATA_INIZIO, D.DATA_FINE AS DATA_FINE
FROM dsb_tmp D
INNER JOIN DiBa P ON D.art_codice_padre = P.art_codice_figlio
)
SELECT art_codice_padre, livello, art_codice_figlio
FROM DiBa
This doesn't work... Why?
Codebue Fabio
.----------------------------------------------------------.
Gestionale Open
Mobile: +39.348.3515786
Web : www.gestionaleopen.org
EMail: fabio.codebue@...
structure and mantain a depth dimensioni into field LIV without haveing a
real field into table.
WITH RECURSIVE
DiBa AS (
SELECT
P.ID AS ID, P.art_codice_padre AS ART_CODICE_PADRE,
P.SEQUENZA AS SEQUENZA, 1 AS LIVELLO,
P.art_codice_figlio AS ART_CODICE_FIGLIO,
P.DESCRIZIONE AS DESCRIZIONE,
P.DATA_INIZIO AS DATA_INIZIO, P.DATA_FINE AS DATA_FINE
FROM dsb_tmp P
WHERE P.utente = :utente AND P.art_codice_padre = :codice_padre
UNION ALL
SELECT
D.ID AS ID, D.art_codice_padre AS ART_CODICE_PADRE,
D.SEQUENZA AS SEQUENZA, (LIVELLO +1) AS LIVELLO,
D.art_codice_figlio AS ART_CODICE_FIGLIO,
D.DESCRIZIONE AS DESCRIZIONE,
D.DATA_INIZIO AS DATA_INIZIO, D.DATA_FINE AS DATA_FINE
FROM dsb_tmp D
INNER JOIN DiBa P ON D.art_codice_padre = P.art_codice_figlio
)
SELECT art_codice_padre, livello, art_codice_figlio
FROM DiBa
This doesn't work... Why?
Codebue Fabio
.----------------------------------------------------------.
Gestionale Open
Mobile: +39.348.3515786
Web : www.gestionaleopen.org
EMail: fabio.codebue@...