The basic syntax for generating XML output in SQL Server is as follows:
SELECT column1, column2, …, columnN FROM table FOR XML mode, root
In the above syntax, the mode parameter specifies the format of the XML output, and the root parameter specifies the name of the root element. The mode parameter can be set to one of the following values:
1. RAW: Generates a single row of XML output for each row in the result set.
2. AUTO: Generates an element for each table column, and a row element for each row in the result set.
3. EXPLICIT: Allows you to define the structure of the XML output using XPath expressions.
We can generate XML output for this table using the following query:
SELECT ID, Name, Department, Salary FROM employees FOR XML AUTO, ROOT('Employees')
The output of the above query will be:
<Employees>
<employees>
<ID>1</ID>
<Name>John</Name>
<Department>Sales</Department>
<Salary>50000</Salary>
</employees>
<employees>
<ID>2</ID>
<Name>Mary</Name>
<Department>Marketing</Department>
<Salary>60000</Salary>
</employees>
<employees>
<ID>3</ID>
<Name>Bill</Name>
<Department>Finance</Department>
<Salary>70000</Salary>
</employees>
</Employees>
I hope it will help you. Thank you :)
For more refer Link: https: