D
D
denislysenko2022-04-07 12:51:44
SQL
denislysenko, 2022-04-07 12:51:44

How to rewrite with as where recursion is used?

there is such a code

WITH ParentDocs AS
(
SELECT doc.DocId, doc.ParentDocGUID, doc.doc_guid, doc.db_id, 0 AS doc_level, doc.DocId
  FROM TV_DocsTableInternet doc
 UNION ALL
SELECT e.DocId, e.ParentDocGUID, e.DocGUID, e.db_id, doc_level + 1, d.Cheque_docid as Cheque_docid
  FROM TV_DCT_Docs e
  JOIN ParentDocs d
    ON e.db_id = d.db_id 
   AND e.doc_guid = d.parent_doc_guid
   AND e.doc_guid <> d.doc_guid
)


In the environment I'm in, with doesn't support recursion.
Is there any other way in SQL to rewrite this with construct to get the ParentDocs that was assembled according to the same logic as in the with construct above? How can I do that? Thank you!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question