LEFT JOIN Base_Unit AS Unit ON WorkArea.UnitId =Unit.UnitId
LEFT JOIN PW_IsoInfo AS IsoInfo on IsoInfo.WorkAreaId = WorkArea.WorkAreaId
--3D-TFM
LEFT JOIN (
SELECT COUNT(distinct a.JOT_ID) as jotNnum, SUM(case when c.CH_TrustType='1' and c.CH_TrustID=e.CH_TrustID then jot_donedin else 0 end) as passdonedin,SUM(case when c.CH_TrustType='2' and JOT_JointStatus !='102' then DefectLength else 0 end) as nopassdonedin, a.ISO_ID
from PW_JointInfo a
left join CH_TrustItem b on a.JOT_ID = b.JOT_ID
left join CH_Trust c on b.CH_TrustID = c.CH_TrustID
left join CH_CheckItem d on a.JOT_ID = d.JOT_ID
left join CH_Check e on e.CHT_CheckID=d.CHT_CheckID
where a.ProjectId=@ProjectId and c.CH_NDTMethod in ('0087dd66-263d-4f7f-8ab7-f4d42b96d815') and e.CHT_CheckDate >= @date1 and e.CHT_CheckDate < @date2
group by a.ISO_ID
) as tfm on tfm.ISO_ID= IsoInfo.ISO_ID
--tofd
LEFT JOIN (
SELECT COUNT(distinct a.JOT_ID) as jotNnum, SUM(case when c.CH_TrustType='1' and c.CH_TrustID=e.CH_TrustID then jot_donedin else 0 end) as passdonedin,SUM(case when c.CH_TrustType='2' and JOT_JointStatus !='102' then DefectLength else 0 end) as nopassdonedin, a.ISO_ID
from PW_JointInfo a
left join CH_TrustItem b on a.JOT_ID = b.JOT_ID
left join CH_Trust c on b.CH_TrustID = c.CH_TrustID
left join CH_CheckItem d on a.JOT_ID = d.JOT_ID
left join CH_Check e on e.CHT_CheckID=d.CHT_CheckID
where a.ProjectId=@ProjectId and c.CH_NDTMethod in ('1b5a29de-b9dd-40af-9176-3f0156e1268b','4ba5ff2a-0a8a-4f60-b549-b2604f72c43e','7d28665b-21fc-45a0-affd-d7b28b9791e1') and e.CHT_CheckDate >= @date1 and e.CHT_CheckDate < @date2
group by a.ISO_ID
) as tofd on tofd.ISO_ID= IsoInfo.ISO_ID
--UT
LEFT JOIN (
SELECT COUNT(distinct a.JOT_ID) as jotNnum, SUM(case when c.CH_TrustType='1' and c.CH_TrustID=e.CH_TrustID then jot_donedin else 0 end) as passdonedin,SUM(case when c.CH_TrustType='2' and JOT_JointStatus !='102' then DefectLength else 0 end) as nopassdonedin, a.ISO_ID
from PW_JointInfo a
left join CH_TrustItem b on a.JOT_ID = b.JOT_ID
left join CH_Trust c on b.CH_TrustID = c.CH_TrustID
left join CH_CheckItem d on a.JOT_ID = d.JOT_ID
left join CH_Check e on e.CHT_CheckID=d.CHT_CheckID
where a.ProjectId=@ProjectId and c.CH_NDTMethod in ('a5e9c1bb-1fad-4e65-82bf-03003cc56ab4') and e.CHT_CheckDate >= @date1 and e.CHT_CheckDate < @date2
group by a.ISO_ID
) as ut on ut.ISO_ID= IsoInfo.ISO_ID
LEFT JOIN (
SELECT COUNT(distinct a.JOT_ID) as jotNnum, SUM(case when c.CH_TrustType='1' and c.CH_TrustID=e.CH_TrustID then jot_donedin else 0 end) as passdonedin,SUM(case when c.CH_TrustType='2' and JOT_JointStatus !='102' then DefectLength else 0 end) as nopassdonedin, a.ISO_ID
from PW_JointInfo a
left join CH_TrustItem b on a.JOT_ID = b.JOT_ID
left join CH_Trust c on b.CH_TrustID = c.CH_TrustID
left join CH_CheckItem d on a.JOT_ID = d.JOT_ID
left join CH_Check e on e.CHT_CheckID=d.CHT_CheckID
where a.ProjectId=@ProjectId and c.CH_NDTMethod in ('c1a39a7f-141f-4243-a23d-34f4c9026d5f') and e.CHT_CheckDate >= @date1 and e.CHT_CheckDate < @date2
group by a.ISO_ID
) as mt on mt.ISO_ID = IsoInfo.ISO_ID
LEFT JOIN (
SELECT COUNT(distinct a.JOT_ID) as jotNnum, SUM(case when c.CH_TrustType='1' and c.CH_TrustID=e.CH_TrustID then jot_donedin else 0 end) as passdonedin,SUM(case when c.CH_TrustType='2' and JOT_JointStatus !='102' then DefectLength else 0 end) as nopassdonedin, a.ISO_ID
from PW_JointInfo a
left join CH_TrustItem b on a.JOT_ID = b.JOT_ID
left join CH_Trust c on b.CH_TrustID = c.CH_TrustID
left join CH_CheckItem d on a.JOT_ID = d.JOT_ID
left join CH_Check e on e.CHT_CheckID=d.CHT_CheckID
where a.ProjectId=@ProjectId and c.CH_NDTMethod in ('2460a5e3-b5fb-40d6-942e-3092ddc11a72') and e.CHT_CheckDate >= @date1 and e.CHT_CheckDate < @date2
group by a.ISO_ID
) as pt on pt.ISO_ID = IsoInfo.ISO_ID
LEFT JOIN (
SELECT COUNT(distinct a.JOT_ID) as jotNnum, SUM(case when d.CHT_CheckResult='合格'then jot_donedin else 0 end) as passdonedin,SUM(case when d.CHT_CheckResult!='合格'then DefectLength else 0 end) as nopassdonedin, a.ISO_ID
from PW_JointInfo a
left join CH_TrustItem b on a.JOT_ID = b.JOT_ID
left join CH_Trust c on b.CH_TrustID = c.CH_TrustID
left join CH_CheckItem d on a.JOT_ID = d.JOT_ID
left join CH_Check e on e.CHT_CheckID=d.CHT_CheckID
where a.ProjectId=@ProjectId and c.CH_TrustType='2' and a.JOT_JointStatus !='102' and c.CH_NDTMethod in ('0087dd66-263d-4f7f-8ab7-f4d42b96d815') and e.CH_TrustID=c.CH_TrustID and c.CH_TrustDate >= @date1 and c.CH_TrustDate < @date2
group by a.ISO_ID
) as tfmback on tfmback.ISO_ID = IsoInfo.ISO_ID
LEFT JOIN (
SELECT COUNT(distinct a.JOT_ID) as jotNnum, SUM(case when d.CHT_CheckResult='合格'then jot_donedin else 0 end) as passdonedin,SUM(case when d.CHT_CheckResult!='合格'then DefectLength else 0 end) as nopassdonedin, a.ISO_ID
from PW_JointInfo a
left join CH_TrustItem b on a.JOT_ID = b.JOT_ID
left join CH_Trust c on b.CH_TrustID = c.CH_TrustID
left join CH_CheckItem d on a.JOT_ID = d.JOT_ID
left join CH_Check e on e.CHT_CheckID=d.CHT_CheckID
where a.ProjectId=@ProjectId and c.CH_TrustType='2' and a.JOT_JointStatus !='102' and c.CH_NDTMethod in ('1b5a29de-b9dd-40af-9176-3f0156e1268b','4ba5ff2a-0a8a-4f60-b549-b2604f72c43e','7d28665b-21fc-45a0-affd-d7b28b9791e1') and e.CH_TrustID=c.CH_TrustID and c.CH_TrustDate >= @date1 and c.CH_TrustDate < @date2
group by a.ISO_ID
) as tofdback on tofdback.ISO_ID = IsoInfo.ISO_ID
LEFT JOIN (
SELECT COUNT(distinct a.JOT_ID) as jotNnum, SUM(case when d.CHT_CheckResult='合格'then jot_donedin else 0 end) as passdonedin,SUM(case when d.CHT_CheckResult!='合格'then DefectLength else 0 end) as nopassdonedin, a.ISO_ID
from PW_JointInfo a
left join CH_TrustItem b on a.JOT_ID = b.JOT_ID
left join CH_Trust c on b.CH_TrustID = c.CH_TrustID
left join CH_CheckItem d on a.JOT_ID = d.JOT_ID
left join CH_Check e on e.CHT_CheckID=d.CHT_CheckID
where a.ProjectId=@ProjectId and c.CH_TrustType='2' and a.JOT_JointStatus !='102' and c.CH_NDTMethod in ('a5e9c1bb-1fad-4e65-82bf-03003cc56ab4') and e.CH_TrustID=c.CH_TrustID and c.CH_TrustDate >= @date1 and c.CH_TrustDate < @date2
group by a.ISO_ID
) as utback on utback.ISO_ID = IsoInfo.ISO_ID
LEFT JOIN (
SELECT COUNT(distinct a.JOT_ID) as jotNnum, SUM(case when d.CHT_CheckResult='合格'then jot_donedin else 0 end) as passdonedin,SUM(case when d.CHT_CheckResult!='合格'then DefectLength else 0 end) as nopassdonedin, a.ISO_ID
from PW_JointInfo a
left join CH_TrustItem b on a.JOT_ID = b.JOT_ID
left join CH_Trust c on b.CH_TrustID = c.CH_TrustID
left join CH_CheckItem d on a.JOT_ID = d.JOT_ID
left join CH_Check e on e.CHT_CheckID=d.CHT_CheckID
where a.ProjectId=@ProjectId and c.CH_TrustType='2' and a.JOT_JointStatus !='102' and c.CH_NDTMethod in ('c1a39a7f-141f-4243-a23d-34f4c9026d5f') and e.CH_TrustID=c.CH_TrustID and c.CH_TrustDate >= @date1 and c.CH_TrustDate < @date2
group by a.ISO_ID
) as mtback on mtback.ISO_ID = IsoInfo.ISO_ID
LEFT JOIN (
SELECT COUNT(distinct a.JOT_ID) as jotNnum, SUM(case when d.CHT_CheckResult='合格'then jot_donedin else 0 end) as passdonedin,SUM(case when d.CHT_CheckResult!='合格' then DefectLength else 0 end) as nopassdonedin, a.ISO_ID
from PW_JointInfo a
left join CH_TrustItem b on a.JOT_ID = b.JOT_ID
left join CH_Trust c on b.CH_TrustID = c.CH_TrustID
left join CH_CheckItem d on a.JOT_ID = d.JOT_ID
left join CH_Check e on e.CHT_CheckID=d.CHT_CheckID
where a.ProjectId=@ProjectId and c.CH_TrustType='2' and a.JOT_JointStatus !='102' and c.CH_NDTMethod in ('2460a5e3-b5fb-40d6-942e-3092ddc11a72') and e.CH_TrustID=c.CH_TrustID and c.CH_TrustDate >= @date1 and c.CH_TrustDate < @date2
group by a.ISO_ID
) as ptback on ptback.ISO_ID = IsoInfo.ISO_ID
LEFT JOIN (
SELECT COUNT(distinct a.JOT_ID) as jotNnum, SUM(case when c.CH_TrustType='1' then jot_donedin else 0 end) as passdonedin,SUM(case when c.CH_TrustType='2' and JOT_JointStatus !='102' then DefectLength else 0 end) as nopassdonedin, a.ISO_ID
from PW_JointInfo a
left join CH_TrustItem b on a.JOT_ID = b.JOT_ID
left join CH_Trust c on b.CH_TrustID = c.CH_TrustID
left join CH_CheckItem d on a.JOT_ID = d.JOT_ID
left join CH_Check e on e.CHT_CheckID = d.CHT_CheckID and e.CH_TrustID = c.CH_TrustID
where a.ProjectId=@ProjectId and e.CHT_CheckDate is not null and c.CH_NDTMethod in ('0087dd66-263d-4f7f-8ab7-f4d42b96d815')
group by a.ISO_ID
) as tfmtotal on tfmtotal.ISO_ID= IsoInfo.ISO_ID
--tofd
LEFT JOIN (
SELECT COUNT(distinct a.JOT_ID) as jotNnum, SUM(case when c.CH_TrustType='1' then jot_donedin else 0 end) as passdonedin,SUM(case when c.CH_TrustType='2' and JOT_JointStatus !='102' then DefectLength else 0 end) as nopassdonedin, a.ISO_ID
from PW_JointInfo a
left join CH_TrustItem b on a.JOT_ID = b.JOT_ID
left join CH_Trust c on b.CH_TrustID = c.CH_TrustID
left join CH_CheckItem d on a.JOT_ID = d.JOT_ID
left join CH_Check e on e.CHT_CheckID = d.CHT_CheckID and e.CH_TrustID = c.CH_TrustID
where a.ProjectId=@ProjectId and e.CHT_CheckDate is not null and c.CH_NDTMethod in ('1b5a29de-b9dd-40af-9176-3f0156e1268b','4ba5ff2a-0a8a-4f60-b549-b2604f72c43e','7d28665b-21fc-45a0-affd-d7b28b9791e1')
group by a.ISO_ID
) as tofdtotal on tofdtotal.ISO_ID= IsoInfo.ISO_ID
--UT
LEFT JOIN (
SELECT COUNT(distinct a.JOT_ID) as jotNnum, SUM(case when c.CH_TrustType='1' then jot_donedin else 0 end) as passdonedin,SUM(case when c.CH_TrustType='2' and JOT_JointStatus !='102' then DefectLength else 0 end) as nopassdonedin, a.ISO_ID
from PW_JointInfo a
left join CH_TrustItem b on a.JOT_ID = b.JOT_ID
left join CH_Trust c on b.CH_TrustID = c.CH_TrustID
left join CH_CheckItem d on a.JOT_ID = d.JOT_ID
left join CH_Check e on e.CHT_CheckID = d.CHT_CheckID and e.CH_TrustID = c.CH_TrustID
where a.ProjectId=@ProjectId and e.CHT_CheckDate is not null and c.CH_NDTMethod in ('a5e9c1bb-1fad-4e65-82bf-03003cc56ab4')
group by a.ISO_ID
) as uttotal on uttotal.ISO_ID= IsoInfo.ISO_ID
LEFT JOIN (
SELECT COUNT(distinct a.JOT_ID) as jotNnum, SUM(case when c.CH_TrustType='1' then jot_donedin else 0 end) as passdonedin,SUM(case when c.CH_TrustType='2' and JOT_JointStatus !='102' then DefectLength else 0 end) as nopassdonedin, a.ISO_ID
from PW_JointInfo a
left join CH_TrustItem b on a.JOT_ID = b.JOT_ID
left join CH_Trust c on b.CH_TrustID = c.CH_TrustID
left join CH_CheckItem d on a.JOT_ID = d.JOT_ID
left join CH_Check e on e.CHT_CheckID = d.CHT_CheckID and e.CH_TrustID = c.CH_TrustID
where a.ProjectId=@ProjectId and e.CHT_CheckDate is not null and c.CH_NDTMethod in ('c1a39a7f-141f-4243-a23d-34f4c9026d5f')
group by a.ISO_ID
) as mttotal on mttotal.ISO_ID = IsoInfo.ISO_ID
LEFT JOIN (
SELECT COUNT(distinct a.JOT_ID) as jotNnum, SUM(case when c.CH_TrustType='1' then jot_donedin else 0 end) as passdonedin,SUM(case when c.CH_TrustType='2' and JOT_JointStatus !='102' then DefectLength else 0 end) as nopassdonedin, a.ISO_ID
from PW_JointInfo a
left join CH_TrustItem b on a.JOT_ID = b.JOT_ID
left join CH_Trust c on b.CH_TrustID = c.CH_TrustID
left join CH_CheckItem d on a.JOT_ID = d.JOT_ID
left join CH_Check e on e.CHT_CheckID = d.CHT_CheckID and e.CH_TrustID = c.CH_TrustID
where a.ProjectId=@ProjectId and e.CHT_CheckDate is not null and c.CH_NDTMethod in ('2460a5e3-b5fb-40d6-942e-3092ddc11a72')
group by a.ISO_ID
) as pttotal on pttotal.ISO_ID = IsoInfo.ISO_ID
where IsoInfo.ProjectId=@ProjectId and ( IsoInfo.Is_Standard=@IsStandard OR @IsStandard = '') ";