在sql server中轉換表XML。
Declare @RESULTXML XML
Declare @SMS_REGISTER TABLE([id] VARCHAR(30),[status] VARCHAR(30))
Declare @EMAIL_REGISTER TABLE([id] VARCHAR(30),[status] VARCHAR(30))
Declare @ODP_REGISTER TABLE([id] VARCHAR(30),[status] VARCHAR(30))
Select @RESULTXML =(
SELECT (SELECT * FROM @SMS_REGISTER FOR XML PATH('sms'), TYPE) AS 'smss',
(SELECT * FROM @EMAIL_REGISTER FOR XML PATH('email'), TYPE) AS 'emails',
(SELECT * FROM @ODP_REGISTER FOR XML PATH('odp'), TYPE) AS 'odps'
FOR XML PATH('subroot'), ROOT('root'))
返回這樣的XML
<root>
<subroot>
<smss>
<sms>
<id>NT0000000020</id>
<status>registered</status>
</sms>
<sms>
<id>NT0000000021</id>
<status>registered</status>
</sms>
<sms>
<id>NT0000000022</id>
<status>registered</status>
</sms>
<sms>
<id>NT0000000023</id>
<status>registered</status>
</sms>
</smss>
<emails>
<email>
<id>NT0000000024</id>
<status>registered</status>
</email>
<email>
<id>NT0000000025</id>
<status>registered</status>
</email>
</emails>
</subroot>
</root>
謝謝,我試圖做一個工會,而不是使用逗號 – BermudaLamb 2012-08-09 18:11:45