Solved

FOR XML EXPLICIT

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

790 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