Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

XML Select

Posted on 2011-03-04
2
Medium Priority
?
321 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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

609 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