Search
 
SCRIPT & CODE EXAMPLE
 

SQL

convert sql query to xml format

-- Use FOR XML PATH('Customer')

SELECT 
   CustomerID as "@CustomerID",
   CompanyName,
   Address as "address/street",
   City as "address/city",
   Region as "address/region",
   PostalCode as "address/zip",
   Country as "address/country",
   ContactName as "contact/name",
   ContactTitle as "contact/title",
   Phone as "contact/phone", 
   Fax as "contact/fax"
FROM Customers
FOR XML PATH('Customer')

-- will result in

  <Customer CustomerID="ALFKI">
    <CompanyName>Alfreds Futterkiste</CompanyName>
    <address>
      <street>Obere Str. 57</street>
      <city>Berlin</city>
      <zip>12209</zip>
      <country>Germany</country>
    </address>
    <contact>
      <name>Maria Anders</name>
      <title>Sales Representative</title>
      <phone>030-0074321</phone>
      <fax>030-0076545</fax>
    </contact>
  </Customer>
Comment

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>
Comment

PREVIOUS NEXT
Code Example
Sql :: flask sqlalchemy session delete 
Sql :: row over partition in sql 
Sql :: pl/sql how to delete a trigger 
Sql :: deletar banco de dados mysql 
Sql :: mysql match in serialized data 
Sql :: python connect to mysql in settings.py 
Sql :: update sqlaclehmy sqlalchemy.orm.evaluator.UnevaluatableError: Cannot evaluate BinaryExpression with operator <function like_op at 0x03CF1DF0 
Sql :: select all domains of database firbird 
Csharp :: how to lock and hide a cursor unity 
Csharp :: count number of enum values C# 
Csharp :: unity if in editor 
Csharp :: unity check collider layer 
Csharp :: aspx textarea 
Csharp :: c# combobox prevent typing 
Csharp :: use enter key unity 
Csharp :: unity get layer of gameobject 
Csharp :: how to call something once in update 
Csharp :: c# string to memorystream 
Csharp :: c# new line in messagebox 
Csharp :: get absolute url c# 
Csharp :: regex for email c# 
Csharp :: current directory in sln file c# 
Csharp :: setup authorize in swagger .net core 
Csharp :: unity textmesh pro 
Csharp :: wait in unity 
Csharp :: c# replace string case insensitive 
Csharp :: c# ipaddress from localhost 
Csharp :: headless chromedriver C# 
Csharp :: unity time.deltatime timescale 0 
Csharp :: set mouse over colors for button wpf 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =