Solved

XML Select

Posted on 2011-03-04
2
313 Views
Last Modified: 2012-05-11
I need to do (one of my first) select as XML statements

I need <?xml version="1.0" encoding="UTF-8" ?> at the top
Then the "root tag" is <Document>
Then a <Header> section with hard coded nodes
Then a <Record> section with firstname, lastname etc nodes

Example would be (selecting first and last name from r_users).
<?xml version="1.0" encoding="UTF-8" ?>
<Document>
  <XMLVersion Version="2.00"/>
  <Header>
       <PacketNum>0000000111222555</PacketNum>
        blah...blah..blah...
  </Header>
  <Record>
     <SeqNum>1</SeqNum>
     <firstName>Bill</firstName>
     <lastName>Gates</lastName>
         blah..blah..blah...
  </Record>
</Document>
0
Comment
Question by:lrbrister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 15

Accepted Solution

by:
derekkromm earned 500 total points
ID: 35036158
declare @t table (
      id int,
      fname varchar(100)
)

insert into @t select 1,'gates' union select 2,'jones'

declare @xml xml
select @xml = '<xml version="1.0" encoding="UTF-8" />
<Document>
  <XMLVersion Version="2.00"/>
  <Header>
       <PacketNum>0000000111222555</PacketNum>
        blah...blah..blah...
  </Header>'
+ (
select
      id, fname
from
      @t
for xml path('Record')
) + '
</Document>'

select @xml
0
 

Author Closing Comment

by:lrbrister
ID: 35036303
Thanks
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how the fundamental information of how to create a table.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question