作为标题,所有开放的思想都受到欢迎
我在我的电脑上测试过,输出似乎是一样的.
例如.
USE BOB_DATABASE SELECT ID,Name,First_Name,Last_Name FROM DBO.T_User FOR XML AUTO USE BOB_DATABASE SELECT ID,Last_Name FROM DBO.T_User FOR XML RAW USE BOB_DATABASE SELECT ID,Last_Name FROM DBO.T_User FOR XML RAW,ELEMENTS USE BOB_DATABASE SELECT ID,Last_Name FROM DBO.T_User FOR XML PATH('CUSTOMERS')
解决方法
XML RAW:结果集中的每一行都被视为一个元素,其中列是属性.
例:
USE BOB_DATABASE SELECT ID,Last_Name FROM DBO.T_User FOR XML RAW;
OUTPUT:
<row id="7801020202083" First_Name="John" Surname="Doe" /> <row id="9812150201082" First_Name="Samantha" Surname="Hill" />
XML AUTO:表名是您的元素
例:
USE BOB_DATABASE SELECT ID,Last_Name FROM DBO.T_User FOR XML AUTO;
OUTPUT:
<DBO.T_USER id="7801020202083" First_Name="John" Surname="Doe" /> <DBO.T_USER id="7801020202083" First_Name="John" Surname="Doe" />
XML路径:表列作为子元素传递.
例:
USE BOB_DATABASE SELECT ID,Last_Name FROM DBO.T_User FOR XML PATH;
OUTPUT:
<row> <id>7801020202083</id> <First_Name>John</First_Name> <Surname>Doe</Surname> </row> <row> <id>7801020202083</id> <First_Name>John</First_Name> <Surname>Doe</Surname> </row>
另请查看此博客https://www.simple-talk.com/sql/learn-sql-server/using-the-for-xml-clause-to-return-query-results-as-xml/为了更好的细分.