想问一下如何在T SQL中创建如下所示的xml doc。
<?xml version="1.0" encoding="UTF-8"?>
<root firstAttribute="test" secondAttribute="test" etc...>
<order firstAttribute="test" secondAttribute="test" etc...></order>
</root>
我真的不知道如何插入多个argumets。
谢谢
答案 0 :(得分:0)
使用** FOR XML将表转换为XML格式**
SELECT TOP 10 *
FROM Customers
inner join Orders on Customers.CustomerID= Orders.CustomerID
FOR XML AUTO
并在前面添加字符串
select '<?xml version="1.0" encoding="UTF-8"?>' + (
SELECT TOP 10 *
FROM Customers
inner join Orders on Customers.CustomerID= Orders.CustomerID
FOR XML AUTO
)
答案 1 :(得分:0)
这将为您提供从表“ TestTable”创建xml所需的逻辑。
DECLARE @TestTable table (firstAttribute int, secondAttribute varchar(100))
INSERT INTO @TestTable values (1,'Test 1')
INSERT INTO @TestTable values (2,'Test 2')
SELECT '<?xml version="1.0" encoding="UTF-8"?>' + (
SELECT
firstAttribute,
secondAttribute
FROM @TestTable
FOR XML PATH ('root')
)