I'm reaching the end of my rope with this project, I'm really hoping someone can help me. I'm tasked with outputting a recordset to a given XML format. I've done so much reading on the topic, my head is spinning. And still nothing is working. If I give you a simple example, hopefully one of you can steer me in the right direction.CREATE TABLE Companies( Company_ID int, Company_Name varchar(10));CREATE TABLE Employees( Company_ID int, Employee_ID int, Employee_Name varchar(20));INSERT INTO CompaniesSELECT 1, 'Acme'UNION ALLSELECT 2, 'SmithCo';INSERT INTO EmployeesSELECT 1, 1, 'Joe'UNION ALLSELECT 1, 2, 'Carol'UNION ALLSELECT 2, 1, 'Dave'UNION ALLSELECT 2, 2, 'Betty';
The output you're expected to provide looks like this:<import xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" type="companies"><companies> <company> <id>1</id> <name>Acme</name> <employees> <employee> <id>1</id> <name>Joe</name> </employee> <employee> <id>2</id> <name>Carol</name> </employee> </employees> </company> <company> <id>2</id> <name>SmithCo</name> <employees> <employee> <id>1</id> <name>Dave</name> </employee> <employee> <id>2</id> <name>Betty</name> </employee> </employees> </company></companies></import>
I've gotten so close with this, but at the moment I'm stuck on a "FOR XML AUTO requires at least one table for generating XML tags" error. If someone could show me how they'd approach this simple example, I'm sure I could work out what I'm doing wrong.Thank you!!!Ron