簡體   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