1. Back To Blog

SQL Server interview questions: - Can we convert a Table Data in to XML format in SQL Server?

This is one of the typical SQL Server interview questions and also the favorable question of the interviewers. The interviewers ask this question to check your skills on converting the table data in to XML format but many of your developer friends fails to answer this question.

Below is the syntax of how to convert table data in to XML format.

Syntax: - Select * From [TableName] For XML Path

So, let demonstrate a sweet and simple example to see how exactly we can convert table data in to XML format using a simple query.

Assume that we have the following Customer's table with their respective data types and data.

Now, let's create a simple query to obtain your required result.

Query: -

Select * from Customer For XML Path

As soon as you execute the above query you will see the result like below diagram.

Now, when you click on the link you will see the XML result like below diagram.

In the above diagram you can clearly see that now your table data has been successfully converted in to the XML format.

Watch the tutorial on Basics SQL Server - Query Plan, Logical/Physical operators.

Do not miss to watch SQL Server Interview Questions video with sample answers :-

Get more video materials on SQL Server interview questions | See more stuffs on author's blog for SQL Server interview questions 

Shiv Prasad Koirala

Visit us @ www.questpond.com or call us at 022-66752917... read more

We are on Social