Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 New and need help with XML? or maybe not

Author  Topic 

sephv1
Starting Member

1 Post

Posted - 2005-10-05 : 17:13:58
Ok, I'm new to SQL and I'm stuck. I'm trying to manipulate some data in a table and put it into an xml file. I've read some of the XML tutorials but can't figure it out...maybe its not the best way to do it. We have software which reads the list of truck numbers and a corresponding ID that goes with it from an XML file. The format of the XML file is like this.

<?xml version="1.0" encoding="utf-8" ?>
<TruckList>
<T100>xxxxxx</T100>
</TruckList>

Currently we build this XML file by hand, but I want to create a proc that builds it based on a table storing the truck numbers and the IDs. So there is a table that has the two columns with this data, I just can't figure out how to pull the data using the XML features of SQL to get it in this format. I don't have to use the XML features if I dont need to. I mean if I could, I wouldn't mind just making another column in the table and just inserting the "<T100>xxxxxx</T100>" for each row, but I couldn't figure that out either....I don't know if this makes sense, hopefully someone out there understands what I'm talking about and can help.

Kristen
Test

22859 Posts

Posted - 2005-10-06 : 04:05:53
Something like this?

DECLARE @Trucks TABLE
(
T100 varchar(10)
)

INSERT INTO @Trucks
SELECT 'A12345'
UNION ALL SELECT 'B67890'

SELECT 10 AS tag,
NULL AS parent,
T100 AS [TruckList!10!T100!element]
FROM @Trucks
FOR XML EXPLICIT

Kristen
Go to Top of Page
   

- Advertisement -