Answers for "Extract Data from SQL Server into XML Format"

SQL
0

Extract Data from SQL Server into XML Format

--SQL Code extract to XML format w/ more explicite and well formed tags than just using "For XML Auto"
    SELECT 
        [EmployeeID] AS '@ID',
        [LastName], [FirstName],
        [Title],
        [BirthDate], [HireDate]
    FROM 
        [dbo].[Employees]
    FOR XML PATH('Employee'), ROOT('Employees')


--Output of This SQL below
    <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>
Posted by: Guest on October-18-2021

Code answers related to "Extract Data from SQL Server into XML Format"

Code answers related to "SQL"

Browse Popular Code Answers by Language