If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How to use XMLQUERY function in ON clause for Join statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-17-09, 01:21
naveen_swiz naveen_swiz is offline
Registered User
 
Join Date: Sep 2009
Posts: 18
How to use XMLQUERY function in ON clause for Join statement

I get the following problem when i tried to create the view using the following statement

CREATE OR REPLACE VIEW TAFJV_FBNK_CUSTOMER_POSITION as
SELECT a.RECID, a.XMLRECORD "THE_RECORD"
,a.RECID "ID"
,XMLCAST(XMLQUERY('$d/row/c1[position()=1]' passing a.XMLRECORD as "d") as VARCHAR(4000)) "DEAL_CCY"
,XMLCAST(XMLQUERY('$d/row/c2[position()=1]' passing a.XMLRECORD as "d") as VARCHAR(4000)) "DEAL_AMOUNT"
FROM
"FBNK_CUSTOMER_POSITION" a
LEFT OUTER JOIN "F_CATEGORY" b
ON b.RECID = XMLCAST(XMLQUERY('$d/row/c15[position()=1]' passing a.XMLRECORD as "d") as VARCHAR(4000))

sqlcode: -338

sqlstate: 42972

The sqlcode says that An ON clause associated with a JOIN operator or in a MERGE statement is not valid .On futher analysis, i could find that XMLQuery function has the restriction that cannot be specified as a part of ON clause that is associated with a JOIN operator.

Is there any other way to perform outer join on XMLQuery function?
Reply With Quote
  #2 (permalink)  
Old 11-17-09, 07:57
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Try XMLTABLE() instead.
Reply With Quote
  #3 (permalink)  
Old 11-18-09, 00:02
naveen_swiz naveen_swiz is offline
Registered User
 
Join Date: Sep 2009
Posts: 18
How to use XMLQUERY function in ON clause for Join statement

I tried to use the XMLTABLE in the on clause as follows

CREATE OR REPLACE VIEW TAFJV_FBNK_CUSTOMER_POSITION as
SELECT a.RECID, a.XMLRECORD "THE_RECORD"
,a.RECID "ID"
,XMLCAST(XMLQUERY('$d/row/c1[position()=1]' passing a.XMLRECORD as "d") as VARCHAR(4000)) "DEAL_CCY"
,XMLCAST(XMLQUERY('$d/row/c2[position()=1]' passing a.XMLRECORD as "d") as VARCHAR(4000)) "DEAL_AMOUNT"
FROM
"FBNK_CUSTOMER_POSITION" a
LEFT OUTER JOIN "F_CATEGORY" b
ON b.RECID = XMLTABLE('$d/row' passing a.XMLRECORD as "d"
COLUMNS
TEST VARCHAR(4000) PATH 'c2')


I get the SQL -104 error code that the statement is incorrect. Is it possible use select statement in a ON Clause?
Reply With Quote
  #4 (permalink)  
Old 11-18-09, 07:30
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
That's not what I meant. You use XMLTABLE() to represent your XML data as a, well, table, then join that table with whatever you need on whatever column makes sense.
Reply With Quote
  #5 (permalink)  
Old 11-18-09, 07:44
naveen_swiz naveen_swiz is offline
Registered User
 
Join Date: Sep 2009
Posts: 18
How to use XMLQUERY function in ON clause for Join statement

thanks for your reply.

Is it possible to do all these things in a single query. Can you please re write the above query?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On