繁体   English   中英

从Sql Server Express 2005检索结构化Xml

[英]Retrieve Structured Xml from Sql Server Express 2005

我想从全文搜索索引表中获取xml输出,如下所示。 但是我的代码在合并我的代码附近生成了错误的语法

SELECT
Table1.Name 'Table1/Name',
Table1.Email 'Table1/Email',
(    SELECT
     Table2.Address 'Address',
     Table2.Phone 'Phone',
     FROM Details Table2
     INNER JOIN Regd Table3 ON Table3.Code = Table2.Code
     AND (Table3.SubCode = xml.SubCode) AND (Table1.Id = Table3.Id)
     FOR XML PATH ('Details'),Type) as 'Table1',
FROM Users Table1
INNER JOIN CONTAINSTABLE(Users,[Name], @SearchKeys) AS KEY_TBL ON Id = KEY_TBL.[KEY]
INNER JOIN Regd Table3 ON Table3.Id = Table1.Id,
OPENXML (@idoc,'/Request/List',2)
WITH (SubCode NVARCHAR(20)) as xml
WHERE  (xml.SubCode = '' or Table3.SubCode = xml.SubCode) AND (Table3.Id = Table1.Id)
FOR XML PATH ('List')
UNION
SELECT
SELECT
Table1.Name 'Table1/Name',
Table1.Email 'Table1/Email',
(    SELECT
     Table2.Address 'Address',
     Table2.Phone 'Phone',
     FROM Details Table2
     INNER JOIN Regd Table3 ON Table3.Code = Table2.Code
     AND (Table3.SubCode = xml.SubCode) AND (Table1.Id = Table3.Id)
     FOR XML PATH ('Details'),Type) as 'Table1',
FROM Users Table1
INNER JOIN CONTAINSTABLE(Users,[Email], @SearchKeys) AS KEY_TBL ON Id = KEY_TBL.[KEY]
INNER JOIN Regd Table3 ON Table3.Id = Table1.Id,
OPENXML (@idoc,'/Request/List',2)
WITH (SubCode NVARCHAR(20)) as xml
WHERE  (xml.SubCode = '' or Table3.SubCode = xml.SubCode) AND (Table3.Id = Table1.Id)
FOR XML PATH ('List')

这是我期望有的

<List>
<Table1>
<Name></Name>
<Email></Email>
<Details>
<Address></Address>
<Phone></Phone>
</Details>
</Table1>
</List>

我认为请求xml参数在这里没有任何用处,因为它只是语法错误

您的代码中有很多语法错误,但是我认为它们在那里,因为您删除了很多您认为不必要的东西。

您说得到的Incorrect syntax near the keyword 'union'

这会给你这个错误,

select *
from YourTable
for xml path('list')
union
select *
from YourTable
for xml path('list')

您必须将查询嵌入到这样的select语句中。

select
(select *
 from YourTable
 for xml path('list'))
union
select
(select *
 from YourTable
 for xml path('list'))

如果您希望The xml data type cannot be selected as DISTINCT because it is not comparable. XML类型,则需要添加type并使用union all因为The xml data type cannot be selected as DISTINCT because it is not comparable.

select
(select *
 from YourTable
 for xml path('list'), type)
union all
select
(select *
 from YourTable
 for xml path('list'), type)

我不知道这是否最终会为您提供所需的输出,但这是Incorrect syntax near the keyword 'union'的原因以及您该怎么办。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM