This is one way:Declare @CaseDetail table ( CaseDetailId int identity(1,1), CaseName varchar(10), Primary Key (CaseDetailId))Declare @Check table ( CheckId int identity(1,1), CaseDetailId int, CheckTypeId int, CheckSuccess bit)Insert Into @CaseDetail Select 'Case 1'Insert Into @CaseDetail Select 'Case 2'Insert Into @CaseDetail Select 'Case 3'Insert Into @CaseDetail Select 'Case 4'Insert Into @Check Select 1, 1, 1Insert Into @Check Select 1, 2, 1Insert Into @Check Select 1, 3, 1Insert Into @Check Select 2, 1, 1Insert Into @Check Select 2, 3, 1Insert Into @Check Select 3, 2, 1Select A.CaseDetailId, A.CaseName, Check1 = SUM(isnull(Case when B.CheckTypeId = 1 then 1 else 0 end,0)), Check2 = SUM(isnull(Case when B.CheckTypeId = 2 then 1 else 0 end,0)), Check3 = SUM(isnull(Case when B.CheckTypeId = 3 then 1 else 0 end,0))From @CaseDetail ALeft Join @Check BOn A.CaseDetailId = B.CaseDetailIdGroup By A.CaseDetailId, A.CaseName
CoreyI Has Returned!!