“Root”SQL返回XML

时间:2016-07-28 18:41:34

标签: sql-server xml

如何更正以下查询以返回xml。 我收到以下错误“第14行:'根'附近的语法错误。 “如何解决这个问题?

declare @v_CurrentDate datetime
set @v_CurrentDate = '2016-07-28'

if exists (select 1
from mydb.dbo.Orders
where OrderDate = @v_CurrentDate)
begin

SELECT 'mydb' AS Client, PrimaryKey, Ship_Status, OrderDate, ApprovedDate, AcknowledgeDate, ShipToSiteName, AntShipDate
FROM mydb.dbo.Orders
WHERE (Ship_Status = 'Acknowledged')
ORDER BY PrimaryKey DESC
for xml auto, type, elements, Root('Orders') 

end
else
select cast('<NoRecords>No order records available for this date.</NoRecords>' as xml)

1 个答案:

答案 0 :(得分:0)

您将不得不提供失败查询的示例。

运行时为SQL Server Management Studio截屏:

create database TestFoo; 
go
use TestFoo
go
create table users (userid int); select userid from users for xml auto, type, elements, root('foo');
go 
use master
go
drop database TestFoo

enter image description here