1

I have code in TSQL for creating a tree, but I am confused: how shall I convert it to mysql ...

CREATE PROCEDURE AccountLedgerViewUnderSundryDebtorCreditorCash  

AS  


WITH GroupInMainGroup (accountGroupId,HierarchyLevel) AS  
(  
select accountGroupId,  
1 as HierarchyLevel  
from tbl_AccountGroup where accountGroupId='27'or accountGroupId = '28'or accountGroupId = '11'  
UNION ALL  
select e.accountGroupId,  
G.HierarchyLevel + 1 AS HierarchyLevel  
from tbl_AccountGroup as e,GroupInMainGroup G  
where e.groupUnder=G.accountGroupId  
)  




SELECT  
ledgerId AS [Account Ledger Id],  
acccountLedgerName AS [Account Ledger Name],  
accountGroupId AS [Account Group Id],  
openingBalance AS [Opening Balance],  
debitOrCredit AS [Credit Or Debit],  
defaultOrNot AS [Editable Or Not],  
description AS [Description]  


FROM tbl_AccountLedger  
where accountGroupId IN (select accountGroupId from GroupInMainGroup)  
pcurry
  • 1,374
  • 11
  • 23
Nisar
  • 5,708
  • 17
  • 68
  • 83
  • 1
    possible duplicate of [How do you use the "WITH" clause in MySQL?](http://stackoverflow.com/questions/1382573/how-do-you-use-the-with-clause-in-mysql) – SchmitzIT Nov 15 '13 at 12:51
  • 2
    MySQL can't do recursive queries. You will need to write a stored procedures that calls itself recursively. –  Nov 15 '13 at 12:58
  • 1
    possible duplicate of [How to transform a MSSQL CTE query to MySQL?](http://stackoverflow.com/questions/8833535/how-to-transform-a-mssql-cte-query-to-mysql) – Ben Nov 15 '13 at 13:23

0 Answers0