How to convert records in a table to XML format using T-SQL?

DECLARE @stSqlString NVARCHAR(MAX)  = ''
DECLARE @stStrXml XML  

           
SET @stSqlString = 'set @stStrXml=(select *  from TableName FOR XML AUTO, elements)'
EXEC sp_executesql @stSqlString, N'@stStrXml XML OUTPUT',@stStrXml OUTPUT

 SELECT  @stStrXml

Post a Comment

0 Comments