Solved

XML Select

Posted on 2011-03-04
2
305 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
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now