我想从表中显示日期,如下所示:
Feb 2017 -24, 25
Feb 2018 -26
我在表中有值:
02/24/2017
02/05/2017
03/31/2017
04/15/2017
02/11/2017
02/25/2017
04/29/2017
我想放弃:
Feb-2017 : 04,05,24,25
March-2017 : 31
Aprial-2017: 15,29
答案 0 :(得分:2)
试试这个:
select datename(month, PackageDate) + ' ' + convert(varchar, year(PackageDate)),
stuff((
select ',' + convert(varchar, day(PackageDate))
from tbl_PackageDate
where datename(month, t2.PackageDate) = datename(month, PackageDate)
and year(PackageDate) = year(t2.PackageDate)
and Packageid = 86
order by PackageDate
for xml path('')
), 1, 1, '')
from tbl_PackageDate t2
where Packageid = 86
group by datename(month, PackageDate),
year(PackageDate);