ALTER VIEW [dbo].[View_JointWelder] AS SELECT jot.JOT_ID,jot.JOT_Size,jot.ProjectId,jot.InstallationId,iso.BSU_ID,jot.JOT_CellWelder AS Welder,w.WED_Unit, jot.STE_ID,jot.DReportID,jot.PointType,jot.RT_FilmNum,jot.RT1_RepairFilm,jot.RT2_RepairFilm, jot.RT2_RepairFilmNum,jot.RT3_RepairFilm,jot.RT3_RepairFilmNum FROM dbo.HJGL_PW_JointInfo jot LEFT JOIN dbo.HJGL_PW_IsoInfo iso ON iso.ISO_ID = jot.ISO_ID LEFT JOIN dbo.HJGL_BS_Welder w on w.WED_ID=jot.JOT_CellWelder WHERE DReportID IS NOT NULL AND JOT_FloorWelder=JOT_CellWelder UNION SELECT jot.JOT_ID,jot.JOT_Size,jot.ProjectId,jot.InstallationId,iso.BSU_ID,jot.JOT_CellWelder AS Welder,w.WED_Unit, jot.STE_ID,jot.DReportID,jot.PointType,jot.RT_FilmNum,jot.RT1_RepairFilm,jot.RT2_RepairFilm, jot.RT2_RepairFilmNum,jot.RT3_RepairFilm,jot.RT3_RepairFilmNum FROM dbo.HJGL_PW_JointInfo jot LEFT JOIN dbo.HJGL_PW_IsoInfo iso ON iso.ISO_ID = jot.ISO_ID LEFT JOIN dbo.HJGL_BS_Welder w on w.WED_ID=jot.JOT_CellWelder WHERE DReportID IS NOT NULL AND JOT_FloorWelder<>JOT_CellWelder UNION SELECT jot.JOT_ID,jot.JOT_Size,jot.ProjectId,jot.InstallationId,iso.BSU_ID,jot.JOT_FloorWelder AS Welder,w.WED_Unit, jot.STE_ID,jot.DReportID,jot.PointType,jot.RT_FilmNum,jot.RT1_RepairFilm,jot.RT2_RepairFilm, jot.RT2_RepairFilmNum,jot.RT3_RepairFilm,jot.RT3_RepairFilmNum FROM dbo.HJGL_PW_JointInfo jot LEFT JOIN dbo.HJGL_PW_IsoInfo iso ON iso.ISO_ID = jot.ISO_ID LEFT JOIN dbo.HJGL_BS_Welder w on w.WED_ID=jot.JOT_FloorWelder WHERE DReportID IS NOT NULL AND JOT_FloorWelder<>JOT_CellWelder GO CREATE PROC [dbo].[HJGL_sp_rpt_welderPerformance3] @unitcode VARCHAR(50) = NULL, @steel VARCHAR(50) = NULL, @WED_Unit NVARCHAR(50) = NULL, @date1 DATETIME = NULL, @date2 DATETIME = NULL, @projectId NVARCHAR(500) = NULL, @installationId NVARCHAR(50)=NULL AS /*焊工业绩分析*/ SELECT NEWID() AS Id, --total.ProjectId, --project.ProjectCode,--施工号 '' as ProjectCode, total.WED_Unit, un.UnitCode,-- 单位代码 un.UnitName,--单位名称 -------------本期start CAST(ISNULL(total.totalSize,0) AS DECIMAL(19,2)) AS totalSize, --总寸径 ISNULL(total.totalJoint,0) AS totalJoint, --总焊口 ISNULL(JointNum1.JointNum1,0) AS JointNum1, --一次拍片焊口数 ISNULL(JointNum1.JointNum1,0)-ISNULL(JointNoPassNum1.JointNoPassNum1,0) AS JointPassNum1, --一次拍片合格焊口数 ISNULL(JointNoPassNum1.JointNoPassNum1,0) AS RepairJoint1, --一次返修焊口数 ISNULL(RepairJoint2.RepairJoint2,0) AS RepairJoint2, --二次返修焊口数 ISNULL(RepairJoint3.RepairJoint3,0) AS RepairJoint3, --三次返修焊口数 CAST((CASE ISNULL((ISNULL(JointNum1.JointNum1,0)-ISNULL(JointNoPassNum1.JointNoPassNum1,0)),0) WHEN 0 THEN 0 ELSE (CASE(ISNULL(JointNum1.JointNum1,0)) WHEN 0 THEN 0 ELSE 1.0 * ISNULL((ISNULL(JointNum1.JointNum1,0)-ISNULL(JointNoPassNum1.JointNoPassNum1,0)),0)/(1.0 * JointNum1.JointNum1) END)END) AS DECIMAL(19,3)) AS JointPassRate , ---一次拍片焊口合格率 ISNULL(JointNum1.totalfilm,0) AS totalfilm, --一次拍片数 (ISNULL(JointNum1.totalfilm,0)- ISNULL(JointNoPassNum2.JointNoPassFilmNum2,0)) AS totalPassfilm, --一次拍片合格数 ISNULL(JointNoPassNum2.JointNoPassFilmNum2,0) AS repairFilm1, --一次返修片子数 ISNULL(RepairJoint2.repairFilm2,0) AS repairFilm2, --二次返修片子数 ISNULL(RepairJoint3.repairFilm3,0) AS repairFilm3, --三次返修片子数 CAST((CASE (ISNULL(JointNum1.totalfilm,0)- ISNULL(JointNoPassNum2.JointNoPassFilmNum2,0)) WHEN 0 THEN 0 ELSE (CASE(ISNULL(JointNum1.totalfilm,0)) WHEN 0 THEN 0 ELSE 1.0 * (ISNULL(JointNum1.totalfilm,0)- ISNULL(JointNoPassNum2.JointNoPassFilmNum2,0))/(1.0 * JointNum1.totalfilm) END) END) AS DECIMAL(19,3)) AS JointFilmPassRate ---一次拍片合格率 FROM --总达因值 --总焊口 (SELECT SUM(joint.JOT_Size) AS totalSize,COUNT(*) AS totalJoint ,joint.WED_Unit FROM View_JointWelder joint LEFT JOIN HJGL_BO_WeldReportMain report ON joint.DReportID = report.DReportID WHERE joint.DReportID IS NOT NULL and (CHARINDEX(joint.ProjectId,@projectId)>0 OR @projectId IS NULL) AND (report.JOT_WeldDate >= @date1 OR @date1 IS NULL) AND (report.JOT_WeldDate <= @date2 OR @date2 IS NULL) AND (joint.ste_id=@steel OR @steel IS NULL) GROUP BY joint.WED_Unit) AS total --一次拍片焊口数 , 一次拍片总数,一次拍片合格总数 LEFT JOIN (SELECT COUNT(joint.JOT_ID) AS JointNum1, SUM(joint.RT_FilmNum) AS totalfilm, joint.WED_Unit FROM dbo.View_JointWelder joint WHERE joint.PointType='点口' AND joint.RT_FilmNum IS NOT NULL and joint.RT_FilmNum>0 and (select COUNT(*) from dbo.HJGL_BO_QualityRating a left join HJGL_CH_TrustItem b on a.CH_TrustItemID=b.CH_TrustItemID left join HJGL_CH_Trust c on b.CH_TrustID=c.CH_TrustID where a.JOT_ID=joint.JOT_ID and FilmNum is not null and c.CH_NDTMethod='20d2cbca-8b3d-434b-b1c1-181796986fa5')>0 AND (joint.ste_id=@steel OR @steel IS NULL) AND joint.dreportid IS NOT NULL and (CHARINDEX(joint.ProjectId,@projectId)>0 OR @projectId IS NULL) AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_BO_QualityRating WHERE JOT_ID=joint.JOT_ID)>= @date1 OR @date1 IS NULL) AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_BO_QualityRating WHERE JOT_ID=joint.JOT_ID)<= @date2 OR @date2 IS NULL) GROUP BY joint.WED_Unit) AS JointNum1 ON JointNum1.WED_Unit = total.WED_Unit --一次拍片不合格焊口数 LEFT JOIN (SELECT COUNT(distinct joint.JOT_ID) AS JointNoPassNum1, joint.WED_Unit FROM dbo.HJGL_CH_RepairItemRecord rr left join dbo.View_JointWelder joint on rr.JOT_ID=joint.JOT_ID WHERE joint.PointType='点口' and rr.NDT_ID='20d2cbca-8b3d-434b-b1c1-181796986fa5' --AND (joint.RT1_RepairFilm IS NOT NULL or (select top 1 CH_TrustItemID from dbo.HJGL_CH_TrustItem ti where ti.JOT_ID=joint.JOT_ID and ti.States='4') is not null) AND (joint.ste_id=@steel OR @steel IS NULL) AND joint.dreportid IS NOT NULL and rr.RepairMark='R1' and (CHARINDEX(joint.ProjectId,@projectId)>0 OR @projectId IS NULL) AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R1')>= @date1 OR @date1 IS NULL) AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R1')<= @date2 OR @date2 IS NULL) GROUP BY joint.WED_Unit) AS JointNoPassNum1 ON JointNoPassNum1.WED_Unit = total.WED_Unit --一次拍片不合格拍片数 LEFT JOIN (SELECT count(rr.RepairItemRecordId) as JointNoPassFilmNum2, joint.WED_Unit FROM dbo.HJGL_CH_RepairItemRecord rr left join dbo.View_JointWelder joint on rr.JOT_ID=joint.JOT_ID WHERE joint.PointType='点口' and rr.NDT_ID='20d2cbca-8b3d-434b-b1c1-181796986fa5' --AND (joint.RT1_RepairFilm IS NOT NULL or (select top 1 CH_TrustItemID from dbo.HJGL_CH_TrustItem ti where ti.JOT_ID=joint.JOT_ID and ti.States='4') is not null) AND (joint.ste_id=@steel OR @steel IS NULL) AND joint.dreportid IS NOT NULL and rr.RepairMark='R1' and (CHARINDEX(joint.ProjectId,@projectId)>0 OR @projectId IS NULL) AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R1')>= @date1 OR @date1 IS NULL) AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R1')<= @date2 OR @date2 IS NULL) GROUP BY joint.WED_Unit) AS JointNoPassNum2 ON JointNoPassNum2.WED_Unit = total.WED_Unit --二次返修拍片焊口数,二次返修拍片总数 LEFT JOIN (SELECT COUNT(joint.JOT_ID) AS RepairJoint2, SUM(ISNULL(joint.RT2_RepairFilmNum,0)) AS RepairFilm2, joint.WED_Unit FROM dbo.View_JointWelder joint WHERE joint.PointType='点口' AND joint.RT2_RepairFilm IS NOT NULL and (CHARINDEX(joint.ProjectId,@projectId)>0 OR @projectId IS NULL) AND (joint.ste_id=@steel OR @steel IS NULL) AND joint.dreportid IS NOT NULL AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R2')>= @date1 OR @date1 IS NULL) AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R2')<= @date2 OR @date2 IS NULL) GROUP BY joint.WED_Unit) AS RepairJoint2 ON RepairJoint2.WED_Unit = total.WED_Unit --三次返修拍片焊口数,三次返修拍片总数 LEFT JOIN (SELECT COUNT(joint.JOT_ID) AS RepairJoint3, SUM(ISNULL(joint.RT3_RepairFilmNum,0)) AS RepairFilm3, joint.WED_Unit FROM dbo.View_JointWelder joint WHERE joint.PointType='点口' AND joint.RT3_RepairFilm IS NOT NULL and (CHARINDEX(joint.ProjectId,@projectId)>0 OR @projectId IS NULL) AND (joint.ste_id=@steel OR @steel IS NULL) AND joint.dreportid IS NOT NULL AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R3')>= @date1 OR @date1 IS NULL) AND ((SELECT TOP 1 SignDate FROM dbo.HJGL_CH_RepairItemRecord WHERE JOT_ID=joint.JOT_ID AND RepairMark='R3')<= @date2 OR @date2 IS NULL) GROUP BY joint.WED_Unit) AS RepairJoint3 ON RepairJoint3.WED_Unit = total.WED_Unit --LEFT JOIN Base_Project project ON total.ProjectId=project.ProjectId LEFT JOIN dbo.Base_Unit un ON un.UnitId=total.WED_Unit WHERE -- (CHARINDEX(total.ProjectId,@projectId)>0 OR @projectId IS NULL) --AND (total.InstallationId = @installationId OR @installationId IS NULL) (un.UnitId=@unitcode OR @unitcode IS NULL) AND (total.WED_Unit = @WED_Unit OR @WED_Unit IS NULL) GO CREATE VIEW [dbo].[View_UnitPerformance] AS SELECT NEWID() AS Id, --total.ProjectId, --project.ProjectCode,--施工号 '' as ProjectCode, total.WED_Unit, un.UnitCode,-- 单位代码 un.UnitName,--单位名称 -------------本期start CAST(ISNULL(total.totalSize,0) AS DECIMAL(19,2)) AS totalSize, --总寸径 ISNULL(total.totalJoint,0) AS totalJoint, --总焊口 ISNULL(JointNum1.JointNum1,0) AS JointNum1, --一次拍片焊口数 ISNULL(JointNum1.JointNum1,0)-ISNULL(JointNoPassNum1.JointNoPassNum1,0) AS JointPassNum1, --一次拍片合格焊口数 ISNULL(JointNoPassNum1.JointNoPassNum1,0) AS RepairJoint1, --一次返修焊口数 ISNULL(RepairJoint2.RepairJoint2,0) AS RepairJoint2, --二次返修焊口数 ISNULL(RepairJoint3.RepairJoint3,0) AS RepairJoint3, --三次返修焊口数 CAST((CASE ISNULL((ISNULL(JointNum1.JointNum1,0)-ISNULL(JointNoPassNum1.JointNoPassNum1,0)),0) WHEN 0 THEN 0 ELSE (CASE(ISNULL(JointNum1.JointNum1,0)) WHEN 0 THEN 0 ELSE 1.0 * ISNULL((ISNULL(JointNum1.JointNum1,0)-ISNULL(JointNoPassNum1.JointNoPassNum1,0)),0)/(1.0 * JointNum1.JointNum1)*100 END)END) AS DECIMAL(19,3)) AS JointPassRate , ---一次拍片焊口合格率 ISNULL(JointNum1.totalfilm,0) AS totalfilm, --一次拍片数 (ISNULL(JointNum1.totalfilm,0)- ISNULL(JointNoPassNum2.JointNoPassFilmNum2,0)) AS totalPassfilm, --一次拍片合格数 ISNULL(JointNoPassNum2.JointNoPassFilmNum2,0) AS repairFilm1, --一次返修片子数 ISNULL(RepairJoint2.repairFilm2,0) AS repairFilm2, --二次返修片子数 ISNULL(RepairJoint3.repairFilm3,0) AS repairFilm3, --三次返修片子数 CAST((CASE (ISNULL(JointNum1.totalfilm,0)- ISNULL(JointNoPassNum2.JointNoPassFilmNum2,0)) WHEN 0 THEN 0 ELSE (CASE(ISNULL(JointNum1.totalfilm,0)) WHEN 0 THEN 0 ELSE 1.0 * (ISNULL(JointNum1.totalfilm,0)- ISNULL(JointNoPassNum2.JointNoPassFilmNum2,0))/(1.0 * JointNum1.totalfilm)*100 END) END) AS DECIMAL(19,3)) AS JointFilmPassRate ---一次拍片合格率 FROM --总达因值 --总焊口 (SELECT SUM(joint.JOT_Size) AS totalSize,COUNT(*) AS totalJoint ,joint.WED_Unit FROM View_JointWelder joint LEFT JOIN HJGL_BO_WeldReportMain report ON joint.DReportID = report.DReportID WHERE joint.DReportID IS NOT NULL GROUP BY joint.WED_Unit) AS total --一次拍片焊口数 , 一次拍片总数,一次拍片合格总数 LEFT JOIN (SELECT COUNT(joint.JOT_ID) AS JointNum1, SUM(joint.RT_FilmNum) AS totalfilm, joint.WED_Unit FROM dbo.View_JointWelder joint WHERE joint.PointType='点口' AND joint.RT_FilmNum IS NOT NULL and joint.RT_FilmNum>0 and (select COUNT(*) from dbo.HJGL_BO_QualityRating a left join HJGL_CH_TrustItem b on a.CH_TrustItemID=b.CH_TrustItemID left join HJGL_CH_Trust c on b.CH_TrustID=c.CH_TrustID where a.JOT_ID=joint.JOT_ID and FilmNum is not null and c.CH_NDTMethod='20d2cbca-8b3d-434b-b1c1-181796986fa5')>0 AND joint.dreportid IS NOT NULL GROUP BY joint.WED_Unit) AS JointNum1 ON JointNum1.WED_Unit = total.WED_Unit --一次拍片不合格焊口数 LEFT JOIN (SELECT COUNT(distinct joint.JOT_ID) AS JointNoPassNum1, joint.WED_Unit FROM dbo.HJGL_CH_RepairItemRecord rr left join dbo.View_JointWelder joint on rr.JOT_ID=joint.JOT_ID WHERE joint.PointType='点口' and rr.NDT_ID='20d2cbca-8b3d-434b-b1c1-181796986fa5' --AND (joint.RT1_RepairFilm IS NOT NULL or (select top 1 CH_TrustItemID from dbo.HJGL_CH_TrustItem ti where ti.JOT_ID=joint.JOT_ID and ti.States='4') is not null) AND joint.dreportid IS NOT NULL and rr.RepairMark='R1' GROUP BY joint.WED_Unit) AS JointNoPassNum1 ON JointNoPassNum1.WED_Unit = total.WED_Unit --一次拍片不合格拍片数 LEFT JOIN (SELECT count(rr.RepairItemRecordId) as JointNoPassFilmNum2, joint.WED_Unit FROM dbo.HJGL_CH_RepairItemRecord rr left join dbo.View_JointWelder joint on rr.JOT_ID=joint.JOT_ID WHERE joint.PointType='点口' and rr.NDT_ID='20d2cbca-8b3d-434b-b1c1-181796986fa5' --AND (joint.RT1_RepairFilm IS NOT NULL or (select top 1 CH_TrustItemID from dbo.HJGL_CH_TrustItem ti where ti.JOT_ID=joint.JOT_ID and ti.States='4') is not null) AND joint.dreportid IS NOT NULL and rr.RepairMark='R1' GROUP BY joint.WED_Unit) AS JointNoPassNum2 ON JointNoPassNum2.WED_Unit = total.WED_Unit --二次返修拍片焊口数,二次返修拍片总数 LEFT JOIN (SELECT COUNT(joint.JOT_ID) AS RepairJoint2, SUM(ISNULL(joint.RT2_RepairFilmNum,0)) AS RepairFilm2, joint.WED_Unit FROM dbo.View_JointWelder joint WHERE joint.PointType='点口' AND joint.RT2_RepairFilm IS NOT NULL AND joint.dreportid IS NOT NULL GROUP BY joint.WED_Unit) AS RepairJoint2 ON RepairJoint2.WED_Unit = total.WED_Unit --三次返修拍片焊口数,三次返修拍片总数 LEFT JOIN (SELECT COUNT(joint.JOT_ID) AS RepairJoint3, SUM(ISNULL(joint.RT3_RepairFilmNum,0)) AS RepairFilm3, joint.WED_Unit FROM dbo.View_JointWelder joint WHERE joint.PointType='点口' AND joint.RT3_RepairFilm IS NOT NULL AND joint.dreportid IS NOT NULL GROUP BY joint.WED_Unit) AS RepairJoint3 ON RepairJoint3.WED_Unit = total.WED_Unit --LEFT JOIN Base_Project project ON total.ProjectId=project.ProjectId LEFT JOIN dbo.Base_Unit un ON un.UnitId=total.WED_Unit