T-Sql将XML列数据作为FOR XML查询中的节点返回

时间:2012-06-29 09:04:19

标签: xml tsql for-xml-path

我在SQL Server 2005中有一个包含一列xml数据的视图。该列来自for xml path()查询,即

SELECT     e.id, eventTypeCode, e.startDate, e.endDate,
(select v.name 
 from venue v inner 
 join eventVenue ev on ev.venueCode=v.code 
 where ev.eventId=e.id for xml path('venue')) as venues    
FROM dbo.event e 
inner join eventType t on e.eventTypeCode=t.code 

我现在想在一个将数据作为xml返回的存储过程中引用此视图,即

create procedure getWebsiteMainCalendarEvents
@startDate datetime,
@endDate datetime
as
select * from vwWebsiteMainCalendar 
 where startDate between @startDate and @endDate 
order by startDate for xml path() element

我希望在运行该过程时视图中的场所显示为子节点,但<>被编码为html实体。有没有办法让xml数据作为输出中的xml节点处理?

1 个答案:

答案 0 :(得分:0)

我已经对它进行了分类。该视图应该在for xml path()上附加了“type”,即

-- VENUES
(select v.name from venue v inner join eventVenue ev on ev.venueCode=v.code where ev.eventId=e.id for xml path('venue'))

应该是

-- VENUES

(从ev.venueCode = v.code中选择场地v内连接eventVenue ev的v.name,其中ev.eventId = e.id用于xml路径('场地'),类型)< / p>