Solved

FOR XML EXPLICIT

Posted on 2011-09-13
2
337 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
[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 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

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

749 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