0

I want to combined mulitple exisiting XML files into one XML output file.

I am a new developer and still learning.

I have a table with four columns - ROWID, XMLMESSAGE, BUS_DTE, DW_LOD.

I want to write a query in teradata that will put several XML messages into one single XML output message.

My current approach is:

SELECT XMLSERIALIZE(
    DOCUMENT XMLELEMENT(NAME "XML_MESSAGES", 
        XMLAGG(XMLMSG)
    ) AS VARCHAR(20000)
) AS transactions_xml
FROM <Database.Table>;

All I get is syntax after syntax error after every edit I make, and I am not sure on how to approach this problem.

Any guidance is hugely appreciated.

1
  • You'll need to give us more to work with. Sample data and desired result. Commented Oct 3, 2024 at 15:24

1 Answer 1

0

although I couldn't test it, I tried to fix syntax errors. check this

SELECT XMLSERIALIZE(
         DOCUMENT XMLELEMENT(
           NAME "XML_MESSAGES", 
           XMLAGG(XMLELEMENT(NAME "Message", XMLMESSAGE))
         ) AS VARCHAR(20000)
       ) AS transactions_xml
FROM <Database.Table>;

EDIT: you can also validate XML with where condition

WHERE XMLMESSAGE IS NULL OR NOT (XMLVALIDATE(XMLMESSAGE));
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you Dervis. I made the edits and the error returned stated 'Error in function XMLELEMENT: Invalid or Null Schema'. What would this represent?
there should be "null" values in XMLMESSAGE. You can exclude nulls or you can consider using COALESCE. you can also consider validation XML. I edited my answer to include that in my answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.