2013-12-17 98 views
0

我已經努力了,但沒有得到solutin譴責sp下面.. plz幫助!努力解決錯誤1064

CREATE PROCEDURE AccountLedgerViewUnderBank() 

begin 


WITH GroupInMainGroup (accountGroupId,HierarchyLevel) AS 
(
select accountGroupId, 
1 as HierarchyLevel 
from tbl_AccountGroup where accountGroupId='9' 
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' 
FROM tbl_AccountLedger 

where accountGroupId IN (select accountGroupId from GroupInMainGroup 
) 
end ; // 

顯示

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that 
corresponds to your MySQL server version for the right syntax to use near 'Group 
InMainGroup (accountGroupId,HierarchyLevel) AS 
(
select accountGroupId, 
1 a' at line 6 
+3

MySQL不支持公共表表達式。您需要升級到允許它們的DBMS。 –

回答

2

它看起來就像你試圖用一個CTE,這是不符合MySQL的支持(在寫作時)錯誤。

子查詢使用MySQL的大多數版本的支持,所以你可以重寫它,就像這樣:

CREATE PROCEDURE AccountLedgerViewUnderBank() 

begin 

SELECT  ledgerId AS 'Account Ledger Id', 
      acccountLedgerName AS 'Account Ledger Name' 
FROM  tbl_AccountLedger 

where  accountGroupId 
    IN  (select accountGroupId 
      from tbl_AccountGroup where accountGroupId='9' 
      UNION ALL 
      select e.accountGroupId 
      from tbl_AccountGroup as e,GroupInMainGroup G 
      where e.groupUnder=G.accountGroupId) 
end ; // 
+0

謝謝..但你錯過了;在第16行結束之前。 +5給你 – gangotri