October 10, 2022 at 2:53 pm
Hi All,
I have this sample xml data with subgroups. I have identified the fields in the source data. I wanted to check if anyone can give me some idea, how can I get the xml output like these from those data. Or someone can point me to the url where I can generate such XML with sub-headers and trailers.
Thanks,
SB009
October 10, 2022 at 2:54 pm
This was removed by the editor as SPAM
October 10, 2022 at 2:58 pm
This was removed by the editor as SPAM
October 10, 2022 at 2:59 pm
This was removed by the editor as SPAM
October 10, 2022 at 3:11 pm
Can you post the XML and your desired results?
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
October 12, 2022 at 11:04 am
This was removed by the editor as SPAM
October 12, 2022 at 3:17 pm
OK, that's an example of the source data. Based on that, what do you want to see? I do not see any 'subgroups' in this example.
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
October 12, 2022 at 5:23 pm
Is this what you're looking for?
DECLARE @MailMessage TABLE (
"to" VARCHAR(100),
"from" VARCHAR(100),
"heading" VARCHAR(100),
"body" VARCHAR(1000)
)
INSERT INTO @MailMessage ("to", "from", "heading", "body")
VALUES
('Tove','Jani','Reminder','Don''t forget me this weekend!')
, ('Jani','Tove','RE: Reminder','Certainly not! Count on me. :-)')
SELECT CONCAT('<?xml version="1.0" encoding="UTF-8"?>','<root>',(SELECT * FROM @MailMessage
FOR XML PATH('note')),'</root>') as XMLout
This will output an XML string that looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<root>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<note>
<to>Jani</to>
<from>Tove</from>
<heading>RE: Reminder</heading>
<body>Certainly not! Count on me. :-)</body>
</note>
</root>
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply