264 lines
29 KiB
Transact-SQL
264 lines
29 KiB
Transact-SQL
UPDATE [dbo].[Batch_BatchTrustItem] SET WeldJointId=
|
||
(SELECT p.WeldJointId FROM [dbo].[Batch_PointBatchItem] p WHERE p.PointBatchItemId=Batch_BatchTrustItem.PointBatchItemId)
|
||
WHERE Batch_BatchTrustItem.WeldJointId IS NULL
|
||
GO
|
||
|
||
|
||
ALTER PROC [dbo].[sp_rpt_UnitWorkareaAnalyze]
|
||
@UnitNo VARCHAR(400) = NULL,
|
||
@AreaNo VARCHAR(50) = NULL,
|
||
@installationId VARCHAR(50) = NULL,
|
||
@ste_steeltype varchar(50) = NULL,
|
||
@startTime datetime = NULL,
|
||
@endTime datetime = NULL,
|
||
@projectId NVARCHAR(50) = NULL
|
||
|
||
AS
|
||
/*单位工区进度分析*/
|
||
SELECT
|
||
WorkArea.ProjectId,
|
||
WorkArea.WorkAreaCode AS baw_areano,--工区代号
|
||
Unit.UnitCode AS bsu_unitcode,--单位代码
|
||
Unit.UnitName AS bsu_unitname, --单位名称
|
||
Installation.InstallationCode, --装置代号
|
||
Installation.InstallationName, --装置名称
|
||
-- 最近焊期
|
||
ISNULL(total.total_jot,0) AS total_jot, --总焊口
|
||
--- 累计数 start
|
||
ISNULL(total_sjot.total_sjot,0) AS total_sjot, --预制总焊口数
|
||
ISNULL(total_fjot.total_fjot,0) AS total_fjot, --安装总焊口数
|
||
ISNULL(cut_total_jot.cut_total_jot,0) AS cut_total_jot, --切除焊口
|
||
CAST(ISNULL(total.total_din,0) AS DECIMAL(19,2)) AS total_din,--总达因
|
||
CAST(ISNULL(total_sjot.total_Sdin,0) AS DECIMAL(19,2)) AS total_Sdin, --预制总达因
|
||
CAST(ISNULL(total_fjot.total_Fdin,0) AS DECIMAL(19,2)) AS total_Fdin, --安装总达因
|
||
ISNULL(finished_total_jot_bq.finished_total_jot_bq,0) AS finished_total_jot_bq, --本期完成焊口数
|
||
ISNULL(finished_total_sjot_bq.finished_total_sjot_bq,0) AS finished_total_sjot_bq, --本期完成预制焊口数
|
||
ISNULL(finished_total_fjot_bq.finished_total_fjot_bq,0) AS finished_total_fjot_bq, --本期完成安装焊口数
|
||
|
||
Convert(nvarchar(10),(CAST((CASE ISNULL(total_jot.total_jot ,0)
|
||
WHEN 0 THEN 0
|
||
ELSE 1.0 * ISNULL(finished_total_jot_bq.finished_total_jot_bq,0) / (1.0 * total_jot.total_jot)
|
||
END) AS DECIMAL(19,3))*100))+'%' AS finisedrate_bq, --本期完成比例
|
||
|
||
convert(nvarchar(10),(CAST((CASE ISNULL(total_jot.total_jot,0)
|
||
WHEN 0 THEN 0
|
||
ELSE 1.0 * ISNULL(finished_total_sjot_bq.finished_total_sjot_bq,0)/ (1.0 *total_jot.total_jot)
|
||
END) AS DECIMAL(19,3))*100))+'%' AS finisedrate_s_bq, -- 本期预制完成比例
|
||
|
||
convert(nvarchar(10),(CAST((CASE ISNULL(total_jot.total_jot,0)
|
||
WHEN 0 THEN 0
|
||
ELSE 1.0 * ISNULL(finished_total_fjot_bq.finished_total_fjot_bq,0)/ (1.0 *total_jot.total_jot)
|
||
END) AS DECIMAL(19,3))*100)) AS finisedrate_f_bq, -- 本期安装完成比例
|
||
|
||
CAST(ISNULL(finished_total_jot_bq.finished_total_din_bq ,0) AS DECIMAL(19,2)) AS finished_total_din_bq, --本期完成达因
|
||
CAST(ISNULL(finished_total_sjot_bq.finished_total_Sdin_bq,0) AS DECIMAL(19,2)) AS finished_total_Sdin_bq,----本期完成预制达因
|
||
CAST(ISNULL(finished_total_fjot_bq.finished_total_Fdin_bq,0) AS DECIMAL(19,2)) AS finished_total_Fdin_bq, ----本期完成安装达因
|
||
|
||
Convert(nvarchar(10),(CAST((CASE ISNULL(total_jot.total_din,0)
|
||
WHEN 0 THEN 0
|
||
ELSE 1.0 * ISNULL(finished_total_jot_bq.finished_total_din_bq ,0)/ (1.0 * total_jot.total_din)
|
||
END) AS DECIMAL(19,3))*100))+'%' AS finisedrate_din_bq, --本期完成达因比例
|
||
convert(nvarchar(10),(CAST((CASE ISNULL(total_jot.total_din,0)
|
||
WHEN 0 THEN 0
|
||
ELSE 1.0 * ISNULL(finished_total_sjot_bq.finished_total_Sdin_bq,0) /(1.0 * total_jot.total_din)
|
||
END) AS DECIMAL(19,3))*100))+'%' AS finisedrate_din_s_bq, -- 本期完成预制达因比例
|
||
convert(nvarchar(10),(CAST((CASE ISNULL(total_jot.total_din,0)
|
||
WHEN 0 THEN 0
|
||
ELSE 1.0 * ISNULL(finished_total_fjot_bq.finished_total_Fdin_bq,0)/ (1.0 * total_jot.total_din)
|
||
END) AS DECIMAL(19,3))*100))+'%' AS finisedrate_din_f_bq, -- 本期完成安装达因比例
|
||
|
||
ISNULL(finished_total_jot.finished_total_jot,0) AS finished_total_jot, --完成焊口
|
||
ISNULL(finished_total_sjot.finished_total_sjot,0) AS finished_total_sjot, --完成预制焊口
|
||
ISNULL(finished_total_fjot.finished_total_fjot,0) AS finished_total_fjot,--完成安装焊口
|
||
|
||
convert(nvarchar(10),(CAST((CASE ISNULL(total_jot.total_jot ,0)
|
||
WHEN 0 THEN 0
|
||
ELSE 1.0 * ISNULL(finished_total_jot.finished_total_jot,0)/ (1.0 * total_jot.total_jot)
|
||
END) AS DECIMAL(19,3))*100))+'%' AS finisedrate, --完成比例
|
||
convert(nvarchar(10),((CAST((CASE ISNULL(total_jot.total_jot,0)
|
||
WHEN 0 THEN 0
|
||
ELSE 1.0 * ISNULL(finished_total_fjot.finished_total_fjot,0) / (1.0 * total_jot.total_jot)
|
||
END) AS DECIMAL(19,3)))*100))+'%' AS finisedrate_f, -- 安装完成比例
|
||
convert(nvarchar(10),((CAST((CASE ISNULL(total_jot.total_jot,0)
|
||
WHEN 0 THEN 0
|
||
ELSE 1.0 * ISNULL(finished_total_sjot.finished_total_sjot,0) / (1.0 * total_jot.total_jot)
|
||
END) AS DECIMAL(19,3)))*100))+'%' AS finisedrate_s, -- 预制完成比例
|
||
|
||
CAST(ISNULL(total_jot.finished_total_din,0) AS DECIMAL(19,2)) AS finished_total_din, --完成达因
|
||
CAST(ISNULL(total_sjot.finished_total_Sdin,0) AS DECIMAL(19,2)) AS finished_total_Sdin,--完成预制达因
|
||
CAST(ISNULL(total_fjot.finished_total_Fdin,0) AS DECIMAL(19,2)) AS finished_total_Fdin, --完成安装达因
|
||
|
||
Convert(nvarchar(10),((CAST((CASE ISNULL(total_jot.total_din,0)
|
||
WHEN 0 THEN 0
|
||
ELSE 1.0 * ISNULL(total_jot.finished_total_din,0) / (1.0 * total_jot.total_din)
|
||
END) AS DECIMAL(19,3)))*100))+'%' AS finisedrate_din, ---完成达因比例
|
||
|
||
convert(nvarchar(10),((CAST((CASE ISNULL(total_jot.total_din,0)
|
||
WHEN 0 THEN 0
|
||
ELSE 1.0 * ISNULL(total_sjot.finished_total_Sdin,0) / (1.0 *total_jot.total_din)
|
||
END) AS DECIMAL(19,3)))*100))+'%' AS finisedrate_din_s, -- 完成预制达因比例
|
||
|
||
convert(nvarchar(10),((CAST((CASE ISNULL(total_jot.total_din,0)
|
||
WHEN 0 THEN 0
|
||
ELSE 1.0 * ISNULL(total_fjot.finished_total_Fdin,0) / (1.0 *total_jot.total_din)
|
||
END) AS DECIMAL(19,3)))*100))+'%' AS finisedrate_din_f -- 完成安装达因比例
|
||
|
||
FROM Project_WorkArea AS WorkArea
|
||
LEFT JOIN Base_Unit AS Unit ON WorkArea.UnitId =Unit.UnitId
|
||
LEFT JOIN Project_Installation AS Installation ON Installation.InstallationId = WorkArea.InstallationId
|
||
|
||
LEFT JOIN (SELECT COUNT(*) total_jot ,Pipeline_Pipeline.WorkAreaId ,SUM(Size) AS total_din
|
||
,SUM(DoneDin) AS finished_total_din
|
||
FROM Pipeline_WeldJoint
|
||
LEFT JOIN Pipeline_Pipeline ON Pipeline_WeldJoint.PipelineId = Pipeline_Pipeline.PipelineId
|
||
LEFT JOIN Base_Material ON Base_Material.MaterialId = Pipeline_WeldJoint.Material1Id
|
||
WHERE (SteelType =@ste_steeltype or @ste_steeltype is null)
|
||
GROUP BY Pipeline_Pipeline.WorkAreaId) AS total ON total.WorkAreaId = WorkArea.WorkAreaId
|
||
|
||
LEFT JOIN (SELECT COUNT(*) total_jot ,Pipeline_Pipeline.WorkAreaId ,SUM(Size) AS total_din
|
||
,SUM(DoneDin) AS finished_total_din
|
||
FROM Pipeline_WeldJoint
|
||
LEFT JOIN Pipeline_Pipeline ON Pipeline_WeldJoint.PipelineId = Pipeline_Pipeline.PipelineId
|
||
LEFT JOIN Base_Material ON Base_Material.MaterialId = Pipeline_WeldJoint.Material1Id
|
||
WHERE Pipeline_WeldJoint.WeldingDailyId is not NULL AND (SteelType =@ste_steeltype or @ste_steeltype is null)
|
||
GROUP BY Pipeline_Pipeline.WorkAreaId) AS total_jot ON total_jot.WorkAreaId = WorkArea.WorkAreaId
|
||
|
||
LEFT JOIN (SELECT COUNT(*) total_sjot ,Pipeline_Pipeline.WorkAreaId, SUM(Size) AS total_Sdin
|
||
,SUM(DoneDin) AS finished_total_Sdin
|
||
FROM Pipeline_WeldJoint
|
||
LEFT JOIN Pipeline_Pipeline ON Pipeline_WeldJoint.PipelineId = Pipeline_Pipeline.PipelineId
|
||
LEFT JOIN Base_Material ON Base_Material.MaterialId =Pipeline_WeldJoint.Material1Id
|
||
WHERE (SteelType =@ste_steeltype or @ste_steeltype is null) and Pipeline_WeldJoint.JointArea='S'
|
||
GROUP BY Pipeline_Pipeline.WorkAreaId) AS total_sjot ON total_sjot.WorkAreaId = WorkArea.WorkAreaId
|
||
|
||
LEFT JOIN (SELECT COUNT(*) total_fjot ,Pipeline_Pipeline.WorkAreaId, SUM(Size) AS total_Fdin
|
||
,SUM(DoneDin) AS finished_total_Fdin
|
||
FROM Pipeline_WeldJoint
|
||
LEFT JOIN Pipeline_Pipeline ON Pipeline_WeldJoint.PipelineId = Pipeline_Pipeline.PipelineId
|
||
LEFT JOIN Base_Material ON Base_Material.MaterialId = Pipeline_WeldJoint.Material1Id
|
||
WHERE (SteelType =@ste_steeltype or @ste_steeltype is null) and Pipeline_WeldJoint.JointArea='F'
|
||
GROUP BY Pipeline_Pipeline.WorkAreaId) AS total_fjot ON total_fjot.WorkAreaId = WorkArea.WorkAreaId
|
||
|
||
LEFT JOIN (SELECT COUNT(*) cut_total_jot ,Pipeline_Pipeline.WorkAreaId
|
||
FROM Pipeline_WeldJoint
|
||
LEFT JOIN Pipeline_Pipeline ON Pipeline_WeldJoint.PipelineId = Pipeline_Pipeline.PipelineId
|
||
LEFT JOIN Base_Material ON Base_Material.MaterialId =Pipeline_WeldJoint.Material1Id
|
||
LEFT JOIN Batch_PointBatchItem ON Batch_PointBatchItem.WeldJointId=Pipeline_WeldJoint.WeldJointId
|
||
WHERE (SteelType =@ste_steeltype or @ste_steeltype is null) and Batch_PointBatchItem.CutDate is not null
|
||
GROUP BY Pipeline_Pipeline.WorkAreaId) AS cut_total_jot ON cut_total_jot.WorkAreaId = WorkArea.WorkAreaId
|
||
|
||
LEFT JOIN (SELECT COUNT(*) finished_total_jot_bq ,Pipeline_Pipeline.WorkAreaId ,SUM(DoneDin) AS finished_total_din_bq
|
||
FROM Pipeline_WeldJoint
|
||
LEFT JOIN Pipeline_Pipeline ON Pipeline_WeldJoint.PipelineId = Pipeline_Pipeline.PipelineId
|
||
LEFT JOIN Base_Material ON Base_Material.MaterialId = Pipeline_WeldJoint.Material1Id
|
||
LEFT JOIN Pipeline_WeldingDaily ON Pipeline_WeldingDaily.WeldingDailyId = Pipeline_WeldJoint.WeldingDailyId
|
||
WHERE (SteelType =@ste_steeltype or @ste_steeltype is null) and Pipeline_WeldJoint.WeldingDailyId is not null
|
||
and (WeldingDate >= @startTime OR @startTime IS NULL) and (WeldingDate <=@endTime OR @endTime IS NULL)
|
||
GROUP BY Pipeline_Pipeline.WorkAreaId) AS finished_total_jot_bq ON finished_total_jot_bq.WorkAreaId = WorkArea.WorkAreaId
|
||
|
||
LEFT JOIN (SELECT COUNT(*) finished_total_sjot_bq ,Pipeline_Pipeline.WorkAreaId,SUM(DoneDin) AS finished_total_Sdin_bq
|
||
FROM Pipeline_WeldJoint
|
||
LEFT JOIN Pipeline_Pipeline ON Pipeline_WeldJoint.PipelineId = Pipeline_Pipeline.PipelineId
|
||
LEFT JOIN Base_Material ON Base_Material.MaterialId = Pipeline_WeldJoint.Material1Id
|
||
LEFT JOIN Pipeline_WeldingDaily ON Pipeline_WeldingDaily.WeldingDailyId = Pipeline_WeldJoint.WeldingDailyId
|
||
WHERE (SteelType =@ste_steeltype or @ste_steeltype is null) and Pipeline_WeldJoint.WeldingDailyId is not null
|
||
and (WeldingDate >= @startTime OR @startTime IS NULL) and (WeldingDate <=@endTime OR @endTime IS NULL)
|
||
and JointArea='S'
|
||
GROUP BY Pipeline_Pipeline.WorkAreaId) AS finished_total_sjot_bq ON finished_total_sjot_bq.WorkAreaId = WorkArea.WorkAreaId
|
||
|
||
LEFT JOIN (SELECT COUNT(*) finished_total_fjot_bq ,Pipeline_Pipeline.WorkAreaId , SUM(DoneDin) AS finished_total_Fdin_bq
|
||
FROM Pipeline_WeldJoint
|
||
LEFT JOIN Pipeline_Pipeline ON Pipeline_WeldJoint.PipelineId = Pipeline_Pipeline.PipelineId
|
||
LEFT JOIN Base_Material ON Base_Material.MaterialId = Pipeline_WeldJoint.Material1Id
|
||
LEFT JOIN Pipeline_WeldingDaily ON Pipeline_WeldingDaily.WeldingDailyId = Pipeline_WeldJoint.WeldingDailyId
|
||
WHERE (SteelType =@ste_steeltype or @ste_steeltype is null) and Pipeline_WeldJoint.WeldingDailyId is not null
|
||
and (WeldingDate >= @startTime OR @startTime IS NULL) and (WeldingDate <=@endTime OR @endTime IS NULL)
|
||
and JointArea='F'
|
||
GROUP BY Pipeline_Pipeline.WorkAreaId) AS finished_total_fjot_bq ON finished_total_fjot_bq.WorkAreaId = WorkArea.WorkAreaId
|
||
|
||
LEFT JOIN (SELECT COUNT(*) finished_total_jot ,Pipeline_Pipeline.WorkAreaId
|
||
FROM Pipeline_WeldJoint
|
||
LEFT JOIN Pipeline_Pipeline ON Pipeline_WeldJoint.PipelineId = Pipeline_Pipeline.PipelineId
|
||
LEFT JOIN Base_Material ON Base_Material.MaterialId = Pipeline_WeldJoint.Material1Id
|
||
WHERE (SteelType =@ste_steeltype or @ste_steeltype is null) and WeldingDailyId is not null
|
||
GROUP BY Pipeline_Pipeline.WorkAreaId) AS finished_total_jot ON finished_total_jot.WorkAreaId = WorkArea.WorkAreaId
|
||
|
||
LEFT JOIN (SELECT COUNT(*) finished_total_sjot ,Pipeline_Pipeline.WorkAreaId
|
||
FROM Pipeline_WeldJoint
|
||
LEFT JOIN Pipeline_Pipeline ON Pipeline_WeldJoint.PipelineId = Pipeline_Pipeline.PipelineId
|
||
LEFT JOIN Base_Material ON Base_Material.MaterialId = Pipeline_WeldJoint.Material1Id
|
||
WHERE (SteelType =@ste_steeltype or @ste_steeltype is null) and WeldingDailyId is not null
|
||
and JointArea='S'
|
||
GROUP BY Pipeline_Pipeline.WorkAreaId) AS finished_total_sjot ON finished_total_sjot.WorkAreaId = WorkArea.WorkAreaId
|
||
|
||
LEFT JOIN (SELECT COUNT(*) finished_total_fjot ,Pipeline_Pipeline.WorkAreaId
|
||
FROM Pipeline_WeldJoint
|
||
LEFT JOIN Pipeline_Pipeline ON Pipeline_WeldJoint.PipelineId = Pipeline_Pipeline.PipelineId
|
||
LEFT JOIN Base_Material ON Base_Material.MaterialId = Pipeline_WeldJoint.Material1Id
|
||
WHERE (SteelType =@ste_steeltype or @ste_steeltype is null) and WeldingDailyId is not null
|
||
and JointArea='F'
|
||
GROUP BY Pipeline_Pipeline.WorkAreaId) AS finished_total_fjot ON finished_total_fjot.WorkAreaId = WorkArea.WorkAreaId
|
||
WHERE
|
||
(WorkArea.ProjectId=@projectId OR @projectId IS NULL ) AND
|
||
(WorkArea.WorkAreaId=@areano OR @AreaNo IS NULL ) AND
|
||
(WorkArea.UnitId=@unitno OR @UnitNo IS NULL) AND
|
||
(WorkArea.InstallationId=@installationId OR @installationId IS NULL)
|
||
|
||
ORDER BY Unit.UnitCode ,Installation.InstallationCode
|
||
|
||
GO
|
||
|
||
|
||
ALTER VIEW [dbo].[View_Batch_PointBatch]
|
||
AS
|
||
/*************点口单视图*************/
|
||
SELECT PointBatch.PointBatchId
|
||
,PointBatch.PointBatchCode
|
||
,PointBatch.ProjectId
|
||
,Project.ProjectCode
|
||
,Project.ProjectName
|
||
,PointBatch.UnitId
|
||
,Unit.UnitName
|
||
,Unit.UnitCode
|
||
,Unit.UnitTypeId
|
||
,PointBatch.InstallationId
|
||
,Installation.InstallationCode
|
||
,Installation.InstallationName
|
||
,PointBatch.DetectionTypeId
|
||
,DetectionType.DetectionTypeCode
|
||
,DetectionType.DetectionTypeName
|
||
,PointBatch.DetectionRateId
|
||
,DetectionRate.DetectionRateCode
|
||
,DetectionRate.DetectionRateValue
|
||
,PointBatch.WelderId
|
||
,Welder.WelderCode
|
||
,Welder.WelderName
|
||
,PointBatch.MediumId
|
||
,Medium.MediumCode
|
||
,Medium.MediumName
|
||
,PointBatch.MaterialId
|
||
,Material.MaterialCode
|
||
,PointBatch.WeldTypeId
|
||
,WeldType.WeldTypeCode
|
||
,WeldType.WeldTypeName
|
||
,PointBatch.StartDate
|
||
,PointBatch.EndDate
|
||
,PointBatch.ClearDate
|
||
,PointBatch.IsTrust
|
||
,PointBatch.IsCheck
|
||
FROM Batch_PointBatch AS PointBatch
|
||
LEFT JOIN Base_Project AS Project ON PointBatch.ProjectId=Project.ProjectId
|
||
LEFT JOIN Base_Unit AS Unit ON PointBatch.UnitId=Unit.UnitId
|
||
LEFT JOIN Project_Installation AS Installation ON PointBatch.InstallationId=Installation.InstallationId
|
||
LEFT JOIN Base_DetectionType AS DetectionType ON PointBatch.DetectionTypeId=DetectionType.DetectionTypeId
|
||
LEFT JOIN Base_DetectionRate AS DetectionRate ON PointBatch.DetectionRateId=DetectionRate.DetectionRateId
|
||
LEFT JOIN Welder_Welder AS Welder ON PointBatch.WelderId=Welder.WelderId
|
||
LEFT JOIN Base_Medium AS Medium ON PointBatch.MediumId=Medium.MediumId
|
||
LEFT JOIN Base_Material AS Material ON PointBatch.MaterialId=Material.MaterialId
|
||
LEFT JOIN Base_WeldType AS WeldType ON PointBatch.WeldTypeId=WeldType.WeldTypeId
|
||
|
||
GO
|
||
|
||
|
||
|