Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8733715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:42:29+00:00 2026-06-13T09:42:29+00:00

I am working on a migration project and need to convert following Oracle query

  • 0

I am working on a migration project and need to convert following Oracle query into it’s SQL Server equivalent.

select SYS_CONNECT_BY_PATH (b.actionnr,'/') as FATHER, SYS_CONNECT_BY_PATH (b.actionnr,'     | ') as REFPATH, LEVEL, 
(select count(p.refactionnr) from zisjob.zj_action p where p.refactionnr=b.actionnr)
Childs, b.* from 
( select NVL(x.ANZFiles,0) ANZFiles, act.actionnr, act.refactionnr, act.lfno, act.jobnr,     act."TYPE", act.actiontype
from zisjob.zj_action act, zisjob.zj_actiontype t, 
( select f.lno, count(f.filenr) as ANZFiles from zisjob.zj_file f where f.lno != f.lfno     Group by f.lno )x
where act.lfno=10 and act.actiontype = t.typeid(+) and act.actionnr = x.lno(+) )
b start with b.actionnr in 
(select b.actionnr from zisjob.zj_action b where b.lfno = 10 and b.refactionnr is    null)
connect by nocycle prior b.actionnr=b.refactionnr order by 1 desc, 2 asc

I am using CTEs to do this. So far, I’ve come up with following :

with h$cte as 
(
   select
      cast (convert(varchar,b.actionnr)+'/' as varchar(max)) as FATHER,
      cast(convert(varchar,b.actionnr)+' | ' as varchar(max)) as REFPATH,
      1 as LEVEL,
      --cast (row_number() over (order by @@spid) as varchar(max)) as LEVEL,
      (select count(p.refactionnr) from zisjob.zj_action p 
       where p.refactionnr = b.actionnr) Childs, 
      b.* 
   from
     (select 
         isnull(x.ANZFiles, 0) ANZFiles, act.actionnr, act.refactionnr, act.lfno,  
         act.jobnr, act."TYPE", act.actiontype
      from zisjob.zj_action act 
      left outer join zisjob.zj_actiontype t on act.actiontype = t.typeid 
      left outer join
          (select f.lno, count(f.filenr) as ANZFiles 
           from zisjob.zj_file f
           where f.lno != f.lfno Group by f.lno ) x on act.actionnr = x.lno
      where act.lfno = 10) b
where 
   b.actionnr in
       (select b.actionnr from zisjob.zj_action b 
        where b.lfno = 10 and b.refactionnr is null)

UNION ALL

select
    CAST(FATHER + '/'+ b.ACTIONNR as varchar(max)) as FATHER,
    CAST(REFPATH + '|'+b.ACTIONNR AS VARCHAR(MAX)) as REFPATH,
    h$cte.LEVEL + 1 as LEVEL,
    (select count(p.refactionnr) from zisjob.zj_action p  
     where p.refactionnr = b.actionnr) Childs, 
    b.*
from
   (select isnull(x.ANZFiles, 0) ANZFiles, act.actionnr, act.refactionnr, 
           act.lfno, act.jobnr, act."TYPE", act.actiontype
    from zisjob.zj_action act 
    left outer join zisjob.zj_actiontype t on act.actiontype = t.typeid 
    left outer join
        (select f.lno, count(f.filenr) as ANZFiles from zisjob.zj_file f
         where f.lno != f.lfno Group by f.lno) x on act.actionnr = x.lno
    where act.lfno = 10) b, 
    h$cte
where 
    b.actionnr in
        (select b.actionnr from zisjob.zj_action b 
         where b.lfno = 10 and b.refactionnr is null)
    and h$cte.ACTIONNR = h$cte.REFACTIONNR
)
select <columns> from h$cte

The translated query giving following errors:

Msg 467, Level 16, State 1, Line 1
GROUP BY, HAVING, or aggregate functions are not allowed in the recursive part of a recursive common table expression ‘h$cte’.

Msg 462, Level 16, State 1, Line 1
Outer join is not allowed in the recursive part of a recursive common table expression ‘h$cte’

How can I work around this? Any help in any form is greatly appreciated. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:42:30+00:00Added an answer on June 13, 2026 at 9:42 am

    I’ve finally solved this as:

    WITH dummy AS(
    
    select isnull(x.ANZFiles,0) ANZFiles, act.actionnr, act.refactionnr, act.lfno, act.jobnr, act."TYPE", act.actiontype
    
    from zisjob.zj_action act left outer join zisjob.zj_actiontype t on act.actiontype = t.typeid left outer join 
    
    ( select f.lno, count(f.filenr) as ANZFiles from zisjob.zj_file f 
    
    where f.lno != f.lfno Group by f.lno )x on act.actionnr = x.lno
    
    where act.lfno=10), 
    
     dummy2 as(
    
    select count(p.refactionnr) as Childs 
    
    from zisjob.zj_action p inner join dummy b on p.refactionnr=b.actionnr
    
    ),
    
    h$cte as(
    
    select 
    
    cast ('/'+convert(varchar,b.actionnr) as varchar(max)) as FATHER, 
    
    cast(' | '+convert(varchar,b.actionnr) as varchar(max)) as REFPATH, 
    
    1 as LEVEL,
    
    c.Childs,
    
    --cast (row_number() over (order by @@spid) as varchar(max)) as LEVEL, 
    
    b.* 
    
    from dummy b, dummy2 c
    
    where b.actionnr in 
    
    (select b.actionnr from zisjob.zj_action b where b.lfno = 10 and b.refactionnr is null)
    
    UNION ALL
    
    select
    
    CAST(FATHER + '/'+ b.ACTIONNR as varchar(max)) as FATHER,
    
    CAST(REFPATH + '|'+b.ACTIONNR AS VARCHAR(MAX)) as REFPATH,
    
    h$cte.LEVEL + 1 as LEVEL,c.Childs,
    
    b.*
    
    from dummy b, dummy2 c, h$cte
    
    where b.actionnr in 
    
    (select b.actionnr from zisjob.zj_action b where b.lfno = 10 and b.refactionnr is null)
    
    and h$cte.ACTIONNR = h$cte.REFACTIONNR
    
    )
    
    select * from h$cte
    

    Since I was not allowed to write outer joins and GROUP BY, HAVING, or aggregate functions inside recursive member of CTE, I’ve moved it outside under a new CTE. That worked like a charm.

    Cheers !!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

recently, while working on a db2 -> oracle migration project, we came across this
I am working on a project that deals with migration of Oracle db to
I'm working on migration of data from a legacy system into our new app(running
I've been working on a rails project, in which I need to firstly seed
I am working on some migration project, involves moving around quite a few stuff
I'm currently working on migration of iPhone project to Android. And since my dev
I am currently working on an Umbraco 4 to 5 migration project . I
We've been working with .Net v3.5 SP1 and MVC 2. Backend SQL Server 2005.
I am working on a jsf migration project. In the process of migration to
I am working on a self project, where I am trying to convert a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.