我最近被介绍给 SSRS,我在从数据库中提取数据时遇到了问题。我在网上搜索,我发现这被称为从多行连接文本。现在,我尝试了一个代码..但在结果中,它给了我彼此相邻的重复数据,用逗号分隔。现在我很高兴它将结果与昏迷分开……但是为什么要给我重复的数据呢?
编码:
select distinct wm1.Date, p1.[Medical Record Number], Wound_Type =CONCAT
((
select distinct CAST(wt2.Name as VARCHAR(MAX))+ ' /// ' from dbo.[Wound Type] as wt2
inner join dbo.[Wound Management] as wm2 on wm2.[Wound Type_ID] = wt2.ID
inner join dbo.Patient as p2 on wm2.[Owner (Patient)_Patient_ID]=p2.ID
where wm1.Date=wm2.Date
FOR XML PATH('')
),wt1.Name)
from dbo.[Wound Type] as wt1
inner join dbo.[Wound Management] as wm1 on wm1.[Wound Type_ID] = wt1.ID
inner join dbo.Patient as p1 on wm1.[Owner (Patient)_Patient_ID]=p1.ID
group by wm1.Date, wt1.Name, p1.[Medical Record Number]
结果:
请帮忙。