select
EV.EmployeeID,
EV.Vacation_Kind,
stuff(( select ', ' + convert(varchar(30), EV1.Value) from EmployeeVacations EV1
where EV1.EmployeeID = EV.EmployeeID and EV1.Vacation_Kind = EV.Vacation_Kind
and EV1.VacationType in ('Adjust','Forward') and EV1.CreationDate IN (EV.CreationDate, dateadd(month, datediff(month, 0, dateadd(month, 1, EV.CreationDate)), 0))
for xml path('')
), 1, 1, '')
from
EmployeeVacations EV
where
EV.EmployeeID = 26 and EV.Vacation_Kind = 'SL'and VacationType = 'Adjust'
group by
EV.EmployeeID, EV.Vacation_Kind, EV.CreationDate
可能這項工作,請嘗試 – BhatiaAshish
這一個完美的工作我去掉後「,其中EV.EmployeeID = 26「,並獲得了我需要的所有記錄。謝謝! – RickCJ7