我在存储过程中组合表时遇到问题。
注意:字段“时间”是 varchar
第一个表 (tbTime)
Time
08:00:00
08:30:00
09:00:00
09:30:00
10:00:00
10:30:00
11:00:00
11:30:00
12:00:00
第二个表(tbClientData)
从 tbclientdata 中选择时间,名称,其中约会='2013/10/26' 按时间排序
Time Name
08:30:00 MaLa
08:35:00 Mara
08:40:00 Sarah
09:00:00 Nafira
09:00:00 Sarah AmeLia
09:00:00 Denur Jumaran
10:00:00 MuLyono
10:00:00 Lucky Strada Nova
我想要这样的条件时间表的结果
Time Name
08:00:00 -
08:30:00 MaLa, Mara, Sarah
09:00:00 Nafira, Sarah AmeLia, Denur Jumaran
09:30:00 -
10:00:00 MuLyono, Lucky Strada Nova
10:30:00 -
11:00:00 -
11:30:00 -
12:00:00 -
感谢阅读或回答^_^
GBU
我试过这个
select c1.Time,
stuff((select distinct ', '+cast(Name as varchar(200))
from tbclientdata c2 where c2.time=c1.time
for xml path('')),1,1,'')
from tbclientdata c1
where c1.Appointment='2013/10/26'
group by c1.Time
结果是……
Time Name
08:30:00 MaLa
08:35:00 Mara, Mr
08:40:00 Sarah
09:00:00 Denur Jumaran, Nafira, Sarah AmeLia, Yason
10:00:00 Lucky Strada Nova, MuLyono