Hi, i have almost a same sort of question, but a bit more detailed one. Can anyone just tell me how to run the following query without using recursive view or temp tables. All i want to do is to merge the recursive part and traditional sql part in a single sql.
Currently with following query i am having a syntax error which is
Failed 6926: definitions, views, triggers or stored procedures
WITH RECURSIVE dealer_part
( dealer_key, dealer_parent_key, depth ) as
(
SELECT dealer_key, dealer_parent_key, 1 as depth
FROM dim_dealers
WHERE dealer_parent_key = -99
AND hierarchy_level = 1
UNION ALL
SELECT dim_dealers.dealer_key, dim_dealers.dealer_parent_key, dealer_part.depth + 1as depth
FROM dealer_part, dim_dealers
WHERE dealer_view.dealer_key = dim_dealers.dealer_parent_key
AND dealer_view.depth < 30
)
select dealer_key
,case when myflag = -999
then 1
else 0
end as bottom_flag
,depth as hierarchy_level
from (
SELECT dp.dealer_key, coalesce(jd.dealer_key,-999) as myflag, dp.depth
FROM dealer_part dp
left join (
select dealer_key
from dim_dealers
where dealer_key in (
select dealer_parent_key
from dim_dealers
group by dealer_parent_key
)
) jd
on dp.dealer_key = jd.dealer_key
) a
thanks in advance
Hi, i have almost a same sort of question, but a bit more detailed one. Can anyone just tell me how to run the following query without using recursive view or temp tables. All i want to do is to merge the recursive part and traditional sql part in a single sql.
Currently with following query i am having a syntax error which is
Failed 6926: definitions, views, triggers or stored procedures
WITH RECURSIVE dealer_part
( dealer_key, dealer_parent_key, depth ) as
(
SELECT dealer_key, dealer_parent_key, 1 as depth
FROM dim_dealers
WHERE dealer_parent_key = -99
AND hierarchy_level = 1
UNION ALL
SELECT dim_dealers.dealer_key, dim_dealers.dealer_parent_key, dealer_part.depth + 1as depth
FROM dealer_part, dim_dealers
WHERE dealer_view.dealer_key = dim_dealers.dealer_parent_key
AND dealer_view.depth < 30
)
select dealer_key
,case when myflag = -999
then 1
else 0
end as bottom_flag
,depth as hierarchy_level
from (
SELECT dp.dealer_key, coalesce(jd.dealer_key,-999) as myflag, dp.depth
FROM dealer_part dp
left join (
select dealer_key
from dim_dealers
where dealer_key in (
select dealer_parent_key
from dim_dealers
group by dealer_parent_key
)
) jd
on dp.dealer_key = jd.dealer_key
) a
thanks in advance