I need to export some data as XML. I have a table (call it Parent) with a PK of ParentID (BIGINT).<br /><br />I have maybe 40 other tables that have ParentID as a field. Not all of these will have records for every ParentID. Some of these table would have additional sub tables.<br /><br />I need to export data in this format<br /><br /><pre><br /><<img src='/community/emoticons/emotion-4.gif' alt=';P' />arent ID="1"><br /> <Table1><br /> <element1>value</element1><br /> <element2>value</element2><br /> </Table1><br /> <Table2><br /> <element1>value</element1><br /> <element2>value</element2><br /> </Table2><br /></Parent><br /><<img src='/community/emoticons/emotion-4.gif' alt=';P' />arent ID="2"><br /> <Table8><br /> <element1>value</element1><br /> <element2>value</element2><br /> <table54><br /> <element>value</element><br /> </table54><br /> </Table1><br /> <Table9><br /> <element1>value</element1><br /> <element2>value</element2><br /> </Table2><br /></Parent><br /></pre><br />The number of elements for each table might be as high as 50 or even a 100.<br /><br />Now I could do this using lots of SELECT statement with UNION ALL and FOR XML EXPLCIT but I'd end up with hundreds (maybe even a thousand) columns in each SELECT statement and it would be a right pain. I'd obviously have to auto generate the code for this.<br /><br />Firstly, is there a limit to the number of columns I can have in a SELECT statement?<br /><br />Secondly, is there a better way of doing this?
.NET DataSet to the rescue and I'm sorted. Loading all the tables into one of these and setting up relationships / XML column mapping then streaming xml to a file and I'm done. I'd recommend it to anyone who needs to export large amounts of XML.