Subject | Re: [firebird-support] something similar to connect by and prior? |
---|---|
Author | Svein Erling Tysvaer |
Post date | 2009-04-08T15:24:56Z |
I don't know Oracle syntax, but in Firebird 2.1 or higher you could do
something like:
WITH RECURSIVE TempTable as (
SELECT A.ID, cast(0 as Integer) as MyLevel, A.Parent_ID
FROM MyTable A
WHERE A.Name = :MyParam
union all
SELECT B.ID, TT.MyLevel+1, B.Parent_ID
FROM MyTable B
JOIN TempTable TT on B.ID = TT.Parent_ID)
SELECT *
FROM TempTable
This is just a very rough sketch, naturally you have to transform it
quite a bit (and if you fail, I'm sure we could help if you tell us an
example of what you want to achieve).
HTH,
Set
Z T Minhas wrote:
something like:
WITH RECURSIVE TempTable as (
SELECT A.ID, cast(0 as Integer) as MyLevel, A.Parent_ID
FROM MyTable A
WHERE A.Name = :MyParam
union all
SELECT B.ID, TT.MyLevel+1, B.Parent_ID
FROM MyTable B
JOIN TempTable TT on B.ID = TT.Parent_ID)
SELECT *
FROM TempTable
This is just a very rough sketch, naturally you have to transform it
quite a bit (and if you fail, I'm sure we could help if you tell us an
example of what you want to achieve).
HTH,
Set
Z T Minhas wrote:
> Hi,
>
> I am using a self referencing table in which i am trying to find
> the level of a field from its parent field. I know that Oracle allows
> for connect by and prior. Is there something similar in firebird? If
> not, I already have a recursive stored procedure which gets all the
> data that I need but it does not calculate the level correctly.
> Any help?
>
> Regards
>
> Z T Minhas