Solved

FOR XML EXPLICIT

Posted on 2011-09-13
2
332 Views
Last Modified: 2012-05-12
Given the attached data, how would I write a select statement FOR XML Explicit. I want the structure to be
<Locations>
  <LocationID=xxx>
  <CinglePointID>xxx</CinglePointID>
   <OPUS_ID>XXX</OPUS_ID>
    etc......
   </LocationID>
  <LocationID=xxxx>
  <CinglePointID>xxx</CinglePointID>
  <OPUS_ID>XXX</OPUS_ID>
     etc...
  </LocationID>
 

</Locations>
 locations.csv
0
Comment
Question by:sherbug1015
2 Comments
 
LVL 59

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 36533132
sherbug1015,

How are you?

First, I am not sure you need FOR XML EXPLICIT here. Second, your attachment doesn't have column names, so my "first" is based on assumptions that the data and resulting XML are pretty flat. Another assumption is the first column is your LocationID column and that your first XML element is really <Location ID="xxx">...</Location>.

With all that said, here is what my first attempt would be:
SELECT LocationID AS "@ID"
     , CinglePointID
     , OPUS_ID
     -- and so on ...
FROM Your_TableName
FOR XML PATH('Location'), TYPE, ROOT('Locations')
;

Open in new window

0
 

Author Closing Comment

by:sherbug1015
ID: 36533206
Perfect.  Thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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

14 Experts available now in Live!

Get 1:1 Help Now