正しいデータを返すレポートを作成しましたが、複数の行ではなく同じ行にグループ化できるかどうか疑問に思っていました。
例が役立ちます!
レポートは現在出力されています
User Count FinishingNextMonth Finishing3Months Finishing6Months
Jo Bloggs 5 Person A
Jo Bloggs 5 Person B
Jo Bloggs 5 Person C
Jo Bloggs 5 Person D
しかし、むしろ出力したい
User Count FinishingNextMonth Finishing3Months Finishing6Months
Jo Bloggs 5 Person A Person B Person C
Jo Bloggs 5 Person D
これは可能ですか?
以下のようにコードします。
declare @startdate datetime
declare @startdateplusone datetime
declare @startdateplusthree datetime
declare @startdateplussix datetime
set @startdate = '30 jul 2013'
set @startdateplusone = DATEADD(mm,1,@startdate)
set @startdateplusthree = DATEADD(mm,3,@startdate)
set @startdateplussix = DATEADD(mm,6,@startdate)
select
u.username + ' ' + u.surname as Consultant,
dbo.GET_CONTRACT_RUNNERS(u.UserId,@startdate) as Runners,
(select fileas from objects where p.ApplicantId = ObjectID and p.EndDate > @startdate and p.EndDate <= @startdateplusone) as FinishingOneMonth,
(select fileas from objects where p.ApplicantId = ObjectID and p.EndDate > @startdateplusone and p.EndDate <= @startdateplusthree) as FinishingThreeMonths,
(select fileas from objects where p.ApplicantId = ObjectID and p.EndDate > @startdateplusthree and p.enddate <= @startdateplussix) as FinishingSixMonths
from placements p
inner join PlacementConsultants pc on pc.PlacementId = p.PlacementID
inner join Users u on u.UserId = pc.UserId
where p.StartDate < @startdate and p.EndDate > @startdate
group by u.UserName, u.Surname, EndDate, ApplicantId, u.userid
order by u.UserName, u.surname