Click here to Skip to main content
15,885,880 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to convert sql server 2008 table to xml file
Posted
Comments
shannya 26-Oct-12 3:10am    
i have sql table contains colomnsSELECT [id]
,[question]
,[qimage1]
,[qimage2]
,[qimage3]
,[status]
FROM [Driving_School].[dbo].[tab_eng_module]
GO
and it has 100 more questions.

i wanted to convert tiis table to xml fle

1 solution

A statement like this (based on the infamous Northwind database):
SQL
SELECT
    [EmployeeID] AS '@ID',
    [LastName], [FirstName],
    [Title],
    [BirthDate], [HireDate]
FROM
    [dbo].[Employees]
FOR XML PATH('Employee'), ROOT('Employees')


Output like this:

XML
<Employees>
  <Employee ID="1">
    <LastName>Davolio</LastName>
    <FirstName>Nancy</FirstName>
    <Title>Sales Representative</Title>
    <BirthDate>1948-12-08T00:00:00</BirthDate>
    <HireDate>1992-05-01T00:00:00</HireDate>
  </Employee>
  <Employee ID="2">
    <LastName>Fuller</LastName>
    <FirstName>Andrew</FirstName>
    <Title>Vice President, Sales</Title>
    <BirthDate>1952-02-19T00:00:00</BirthDate>
    <HireDate>1992-08-14T00:00:00</HireDate>
  </Employee>


Use the following links:

http://social.msdn.microsoft.com/Forums/pl/sqlxml/thread/5915dc22-562c-44ab-bd4d-041d43f47f1c[^]
http://stackoverflow.com/questions/3952469/export-xml-from-sql-server[^]
http://stackoverflow.com/questions/1564541/how-to-convert-records-in-a-table-to-xml-format-using-t-sql[^]


Thanks,
Ambesha
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900