Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

FOR XML EXPLICIT

Posted on 2011-09-13
2
Medium Priority
?
346 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 60

Accepted Solution

by:
Kevin Cross earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
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.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

782 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