Tuesday 21 June 2011

FOR XML with SQL queries

id test
----------- -----------
1 prk
2 prk1
3 prk2


select * from dbo.aaaa1 for xml raw

Output:




select * from dbo.aaaa1 for XML AUTO

Output:




select * from dbo.aaaa1 for xml auto,elements

Output:

1prk2prk1
3prk2

select * from dbo.aaaa1 for XML AUTO ,Elements XSINIL

Output:
Give same o/p as above but maps null value also. The ELEMENTS directive provides an XSINIL option to map NULL values to an element with an attribute xsi:nil="true".

1prk2prk1
3prk2