摘要:table 轉成 xml ;xml 轉成字串
DECLARE @SQL VARCHAR(1000)=''
DECLARE @XmlDoc XML
DECLARE @strXML VARCHAR(MAX)=''
--將TABLE轉成XML文件
SELECT @XmlDoc =(
SELECT TOP 2 *
FROM TableName
FOR XML RAW('Row'),ELEMENTS,ROOT('TableName')
)
SELECT @XmlDoc AS XmlDoc
--將XML文件轉成字串
SELECT @strXML = CONVERT(VARCHAR(MAX),@XmlDoc)
SELECT @strXML AS strXML