I need to create a xml tree by writing a sql query. This is what I have so far:
The Portfolios element needs to have attributes and the PortfolioLink element needs to have a parent element that also has attributes. Is there an easier way to do this then the sql that I've started writing? I don't find it easy to add a parent element and include attributes to that parent element.
Code:
SELECT (SELECT CAST(upd_date AS date) AS '@EffectiveDate'
,SUBSTRING(entity_id, 2, 3) AS '@PortfolioCode'
,legal_name AS '@PortfolioGroup'
,'' AS '@IntlDomesticInd'
FROM Entity
FOR
XML PATH('Portfolio'),
TYPE),
(SELECT ED.entity_id AS '@GroupCode'
,RTRIM(ED.entity_detail_id) AS '@PortfolioCode'
,'' AS '@IntlDomesticInd'
FROM entity_detail ED
FOR
XML PATH('PortfolioLink'),
TYPE
)
FOR XML PATH('Portfolios')
GO