I have an account table and a campaign table, each account has certain number of campaigns associated with it. No I want to export the account IDs and all the Campaign IDs associated with that account id in to XML in this structure
<Accounts>
<Account>
<AccountID></AccountID>
<AccountName></AccountName>
<CampaignIDs>
<CampaignID></CampaignID>
<CampaignID></CampaignID>
</CampaignIDs>
</Account>
</Accounts>
I am using XML Explicit to control the output of the data into XML and here is what I have got so far.
SELECT
1 AS Tag,
NULL AS Parent,
NULL AS 'Accounts!1',
NULL AS 'Account!2!AccountID!Element',
NULL AS 'Account!2!AccountName!Element',
NULL AS 'Account!2!FMID!Element'
UNION ALL
SELECT
2 AS Tag,
1 AS Parent,
NULL,
a.id as AccountID,
a.Name as AccountName,
NULL
from Account a
FOR XML EXPLICIT
Now I want to execute another query like Select id from campaign where accountid = var
and then append all those campaign IDs to the xml structure.
How do I go about this?