0

我正在使用 coalesce 返回一串名称,当我将它作为单个查询运行时,我没有问题,但是当我想将它放在更大的查询中时,我有点难过。

以下是有效的部分:

DECLARE @return varchar(200)

SELECT @return = COALESCE(@return + ', ', '') +
                 CAST((select FileAs) AS varchar(30))
from Objects
where ObjectId in (select objectid from  dbo.Get_XML_Links(2335))
select @return

但我想将名称列表添加到更大的查询中,如下所示:

select  det.Description,
        StartTime, 
        EndTime,
        THE STRING OF NAMES

from DiaryEvents de
inner join DiaryEventTypes det on det.DiaryEventTypeID = de.EventTypeID
where EventTypeID in (29,40)

我不太清楚我需要做什么(或者是否可以采用这种格式!)

4

1 回答 1

0

感谢上面的评论和一篇关于SQL Authority的非常方便的文章,我已经完成了如下工作:

select  det.Description,
        StartTime, 
        EndTime, 
        (
        SELECT SUBSTRING(
        (select ',' + FileAs
        from Objects
        where ObjectId in (select objectid from dbo.Get_XML_Links(de.diaryeventid) where ObjectTypeSystemCode = 'CCT')
        FOR XML PATH('')),2,200000) 
        )AS Contacts


from DiaryEvents de
inner join DiaryEventTypes det on det.DiaryEventTypeID = de.EventTypeID
where EventTypeID in (29,40)
于 2012-09-17T15:44:46.817 回答