dbTalk Databases Forums  

DB2 SQL0345N

comp.databases.ibm-db2 comp.databases.ibm-db2


Discuss DB2 SQL0345N in the comp.databases.ibm-db2 forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
scv1977
 
Posts: n/a

Default DB2 SQL0345N - 04-25-2010 , 11:10 PM






Hi
I have the following build problem with SQL executing the following.
(Conversion MSSQL to DB2)
The simplified code does the following(SQL0345N)
DB2 Verson is DBUDB9.7(Fix1)


WITH CTE_Tree(Seq1, Seq2,Type, TypeSeq, ItemSeq,CostType,Sort,
Level)
AS
(

SELECT A.Seq1, A.Seq2, A.Type, A.TypeSeq, A.itemSeq,
A.CostType, A.Sort, A.Level
FROM dbo."FORMTREE" A
WHERE A.Seq1 = 1
AND A.Seq2 = 1277
AND A.TypeSeq = 2
AND A.ItemSeq = 926
AND A.CostType = 0

UNION ALL

SELECT A.Seq1, A.Seq2, A.Type, A.TypeSeq, A.itemSeq,
A.CostType, A.Sort, A.Level

FROM dbo."FORMTREE" A
INNER JOIN CTE_Tree CTE
ON A.TypeSeq = CTE.TypeSeq
AND A.ItemSeq = CTE.ItemSeq
AND A.CostType = CTE.CostType
WHERE A.Seq1 = 1
AND A.Seq2 = 1277)
select Seq1,Seq2 from CTE_Tree

--->SQL0345N The fullselect of the recursive common table expression
" CTE_Tree" must be the UNION of two or more fullselects and
cannot include column functions, GROUP BY clause, HAVING clause,
ORDER BY clause, or an explicit join including an ON clause.

Can't I change MSSQL code to DB2??

Reply With Quote
  #2  
Old   
danfan46
 
Posts: n/a

Default Re: DB2 SQL0345N - 04-26-2010 , 12:06 AM






scv1977 wrote:
Quote:
Hi
I have the following build problem with SQL executing the following.
(Conversion MSSQL to DB2)
The simplified code does the following(SQL0345N)
DB2 Verson is DBUDB9.7(Fix1)


WITH CTE_Tree(Seq1, Seq2,Type, TypeSeq, ItemSeq,CostType,Sort,
Level)
AS
(

SELECT A.Seq1, A.Seq2, A.Type, A.TypeSeq, A.itemSeq,
A.CostType, A.Sort, A.Level
FROM dbo."FORMTREE" A
WHERE A.Seq1 = 1
AND A.Seq2 = 1277
AND A.TypeSeq = 2
AND A.ItemSeq = 926
AND A.CostType = 0

UNION ALL

SELECT A.Seq1, A.Seq2, A.Type, A.TypeSeq, A.itemSeq,
A.CostType, A.Sort, A.Level

FROM dbo."FORMTREE" A
INNER JOIN CTE_Tree CTE
ON A.TypeSeq = CTE.TypeSeq
AND A.ItemSeq = CTE.ItemSeq
AND A.CostType = CTE.CostType
WHERE A.Seq1 = 1
AND A.Seq2 = 1277)
select Seq1,Seq2 from CTE_Tree

--->SQL0345N The fullselect of the recursive common table expression
" CTE_Tree" must be the UNION of two or more fullselects and
cannot include column functions, GROUP BY clause, HAVING clause,
ORDER BY clause, or an explicit join including an ON clause.

Can't I change MSSQL code to DB2??




Is dbo a valid schema name in your database



/dg

Reply With Quote
  #3  
Old   
danfan46
 
Posts: n/a

Default Re: DB2 SQL0345N - 04-26-2010 , 12:11 AM



scv1977 wrote:
Quote:
Hi
I have the following build problem with SQL executing the following.
(Conversion MSSQL to DB2)
The simplified code does the following(SQL0345N)
DB2 Verson is DBUDB9.7(Fix1)


WITH CTE_Tree(Seq1, Seq2,Type, TypeSeq, ItemSeq,CostType,Sort,
Level)
AS
(

SELECT A.Seq1, A.Seq2, A.Type, A.TypeSeq, A.itemSeq,
A.CostType, A.Sort, A.Level
FROM dbo."FORMTREE" A
WHERE A.Seq1 = 1
AND A.Seq2 = 1277
AND A.TypeSeq = 2
AND A.ItemSeq = 926
AND A.CostType = 0

UNION ALL

SELECT A.Seq1, A.Seq2, A.Type, A.TypeSeq, A.itemSeq,
A.CostType, A.Sort, A.Level

FROM dbo."FORMTREE" A
INNER JOIN CTE_Tree CTE
ON A.TypeSeq = CTE.TypeSeq
AND A.ItemSeq = CTE.ItemSeq
AND A.CostType = CTE.CostType
WHERE A.Seq1 = 1
....



WITH T1 (Seq1, Seq2,Type, TypeSeq, ItemSeq,CostType,Sort,Level)
AS
(
SELECT A.Seq1, A.Seq2, A.Type, A.TypeSeq, A.itemSeq,
A.CostType, A.Sort, A.Level
FROM "FORMTREE" A
WHERE A.Seq1 = 1
AND A.Seq2 = 1277
AND A.TypeSeq = 2
AND A.ItemSeq = 926
AND A.CostType = 0
UNION ALL
SELECT A.Seq1, A.Seq2, A.Type, A.TypeSeq, A.itemSeq,
A.CostType, A.Sort, A.Level
FROM "FORMTREE" A
INNER JOIN CTE_Tree CTE
ON A.TypeSeq = CTE.TypeSeq
AND A.ItemSeq = CTE.ItemSeq
AND A.CostType = CTE.CostType
WHERE A.Seq1 = 1
AND A.Seq2 = 1277
)
select Seq1,Seq2
from T1
;
/dg

Reply With Quote
  #4  
Old   
Tonkuma
 
Posts: n/a

Default Re: DB2 SQL0345N - 04-26-2010 , 01:04 AM



The message text explained the cause of the error.

--->SQL0345N The fullselect of the recursive common table expression
"CTE_Tree" .....
cannot include ..... or an explicit join including an ON clause.

Please try
....
....
FROM dbo."FORMTREE" A
, CTE_Tree CTE
WHERE A.TypeSeq = CTE.TypeSeq
AND A.ItemSeq = CTE.ItemSeq
AND A.CostType = CTE.CostType
AND A.Seq1 = 1
AND A.Seq2 = 1277)
....

Reply With Quote
  #5  
Old   
Tonkuma
 
Posts: n/a

Default Re: DB2 SQL0345N - 04-26-2010 , 01:12 AM



Another issue I thought was that both of first and second selects in
CTE "CTE_Tree" have actualy same conditions for table dbo."FORMTREE".

So, the CTE is nonsense and may fall into infinite loop.

Reply With Quote
  #6  
Old   
scv1977
 
Posts: n/a

Default Re: DB2 SQL0345N - 04-26-2010 , 02:00 AM



Actually ,DBO Schema is right..

Tonkuma!!
In place of INNER JOIN,
(FROM dbo."FORMTREE" A
, CTE_Tree CTE) is good point!!.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.