HOW TO SHOW SQL SERVER XML FORMAT DATA

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
 711  View(s)
Ratings:
Rate this:
I want to show data XML format  in sql server please help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: How to show SQL Server XML format Data

    SQL Server lets you retrieve data as XML by supporting the FOR XML clause, which can be included as part of your query. You can use the FOR XML clause in the main (outer) query as well as in subqueries. The clause supports numerous options that let you define the format of the XML data.
    The AUTO mode in a FOR XML clause is slightly different from the RAW mode in the way that it generates the XML result set. The AUTO mode generates the XML by using heuristics based on how the SELECT statement is defined.

    select * from Employee
     SELECT Emp_ID, Emp_Name,Emp_Sal
    FROM Employee 
     FOR XML AUTO;
    <Employee Emp_ID="1" Emp_Name="Amit" Emp_Sal="100000.00"/>
     <Employee Emp_ID="2" Emp_Name="Mohan" Emp_Sal="1200.00"/>
     <Employee Emp_ID="3" Emp_Name="Avin" Emp_Sal="1100.00"/>
     <Employee Emp_ID="4" Emp_Name="Manoj" Emp_Sal="1300.00"/>
     <Employee Emp_ID="5" Emp_Name="Riyaz" Emp_Sal="1400.00"/>
     <Employee Emp_ID="7" Emp_Name="Shukla" Emp_Sal="9200.00"/>
     <Employee Emp_ID="8" Emp_Name="Shailu" Emp_Sal="900.00"/>
     <Employee Emp_ID="9" Emp_Name="Shailu" Emp_Sal="900.00"/>
     <Employee Emp_ID="10" Emp_Name="Vivek" Emp_Sal="5000.00"/>
     <Employee Emp_ID="11" Emp_Name="Manoj" Emp_Sal="5000.00"/>
     <Employee Emp_ID="12" Emp_Name="Suraj" Emp_Sal="51200.00"/>
     <Employee Emp_ID="13" Emp_Name="vrijesh" Emp_Sal="544200.00"/>
     <Employee Emp_ID="14" Emp_Name="rakesh" Emp_Sal="879252.00"/>
     <Employee Emp_ID="15" Emp_Name="avishek" Emp_Sal="45000.00"/>
     <Employee Emp_ID="16" Emp_Name="manish" Emp_Sal="10000.00"/>
     <Employee Emp_ID="17" Emp_Name="suresh" Emp_Sal="5000.00"/>
     <Employee Emp_ID="18" Emp_Name="pradeep" Emp_Sal="45000.00"/>
     <Employee Emp_ID="19" Emp_Name="kamlesh" Emp_Sal="45000.00"/>
     <Employee Emp_ID="20" Emp_Name="arun" Emp_Sal="45000.00"/>
     <Employee Emp_ID="21" Emp_Name="ahiv" Emp_Sal="78210.00"/>
     <Employee Emp_ID="22" Emp_Name="vimal" Emp_Sal="9411.00"/>
     <Employee Emp_ID="23" Emp_Name="vijay" Emp_Sal="15452.00"/>
     <Employee Emp_ID="24" Emp_Name="rajeev" Emp_Sal="78900.00"/>

      Modified On Nov-30-2015 09:50:00 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!