184 lines
		
	
	
		
			8.9 KiB
		
	
	
	
		
			Transact-SQL
		
	
	
	
			
		
		
	
	
			184 lines
		
	
	
		
			8.9 KiB
		
	
	
	
		
			Transact-SQL
		
	
	
	
INSERT INTO dbo.Base_UnitType(UnitTypeId, UnitTypeName)
 | 
						||
VALUES ( '6','管理公司' )
 | 
						||
GO
 | 
						||
 | 
						||
 | 
						||
ALTER PROCEDURE [dbo].[sp_TrustReport]
 | 
						||
(
 | 
						||
   @TrustBatchId NVARCHAR(50)
 | 
						||
)
 | 
						||
AS
 | 
						||
SELECT 
 | 
						||
('工程名称:'+pro.ProjectName) AS ProjectName,pro.EnProjectName,trust.TrustDate,
 | 
						||
('单元名称:'+area.WorkAreaName) AS WorkAreaName, area.EnWorkAreaName,
 | 
						||
(SELECT unit.UnitName FROM dbo.Project_Unit punit LEFT JOIN dbo.Base_Unit unit ON unit.UnitId = punit.UnitId WHERE ProjectId= trust.ProjectId AND punit.UnitType='1') AS TrustUnit,
 | 
						||
trust.TrustBatchCode,nde.DetectionTypeCode,trust.SurfaceState,nde.TestStandard,rate.DetectionRateCode, nde.TechLevel,
 | 
						||
(CASE WHEN trust.NDEUuit IS NOT NULL THEN unit.UnitName ELSE (SELECT UnitName FROM dbo.Base_Unit WHERE UnitId=(SELECT TOP 1 UnitId FROM dbo.Project_Unit WHERE ProjectId= trust.ProjectId AND UnitType='4')) END) AS NDEUnit,
 | 
						||
 mat.WeldingMethodCode,groove.GrooveTypeCode,pipe.PipelineCode,trust.DetectionTiming,
 | 
						||
(CASE WHEN nde.SysType='渗透检测' THEN 'Ⅰ' ELSE (CASE WHEN nde.SysType='超声波检测' THEN 'Ⅱ' ELSE (CASE WHEN rate.DetectionRateCode='5%' OR rate.DetectionRateCode='10%' THEN 'Ⅲ' ELSE 'Ⅱ' END) END)END) AS QueClass,
 | 
						||
 | 
						||
trust.QuaCertFile,--质量证明文件编号
 | 
						||
trust.AcceptStandard--制造/验收标准
 | 
						||
FROM dbo.Batch_BatchTrust trust 
 | 
						||
LEFT JOIN dbo.Base_Project pro ON pro.ProjectId = trust.ProjectId
 | 
						||
--LEFT JOIN dbo.Project_Installation ins ON ins.InstallationId = trust.InstallationId
 | 
						||
LEFT JOIN dbo.Project_WorkArea area ON area.WorkAreaId = trust.WorkAreaId
 | 
						||
LEFT JOIN dbo.Base_Unit unit ON unit.UnitId = trust.NDEUuit
 | 
						||
LEFT JOIN dbo.Base_Unit cunit ON cunit.UnitId = trust.UnitId
 | 
						||
--LEFT JOIN dbo.Base_Unit tunit ON tunit.UnitId = ins.SupervisorUnitId
 | 
						||
LEFT JOIN dbo.Base_DetectionType nde ON nde.DetectionTypeId = trust.DetectionTypeId
 | 
						||
LEFT JOIN dbo.Base_WeldingMethod mat ON mat.WeldingMethodId = trust.WeldingMethodId
 | 
						||
LEFT JOIN dbo.Base_GrooveType groove ON groove.GrooveTypeId = trust.GrooveTypeId
 | 
						||
LEFT JOIN dbo.Pipeline_Pipeline pipe ON pipe.PipelineId = trust.PipelineId
 | 
						||
LEFT JOIN dbo.Base_DetectionRate rate ON rate.DetectionRateId = pipe.DetectionRateId
 | 
						||
WHERE trust.TrustBatchId=@TrustBatchId
 | 
						||
 | 
						||
GO
 | 
						||
 | 
						||
 | 
						||
ALTER PROCEDURE [dbo].[TrustItemReport]
 | 
						||
(
 | 
						||
   @TrustBatchId NVARCHAR(50)
 | 
						||
)
 | 
						||
AS
 | 
						||
/******焊缝检测委托单明细表*******/	  
 | 
						||
SELECT	ROW_NUMBER() OVER(ORDER BY jot.WeldJointCode) AS Number,
 | 
						||
BatchTrustItem.TrustBatchItemId, 
 | 
						||
BatchTrustItem.TrustBatchId, 
 | 
						||
pipe.PipelineCode,     --管线号
 | 
						||
pipe.SingleNumber,     --单线号
 | 
						||
(CASE WHEN PointBatchItem.PointState='2' then (CASE WHEN jot.JointAttribute='固定F' THEN 'F'+jot.WeldJointCode ELSE 'S'+jot.WeldJointCode END)+'K'
 | 
						||
      ELSE (CASE WHEN jot.JointAttribute='固定F' THEN 'F'+jot.WeldJointCode ELSE 'S'+jot.WeldJointCode END) END) AS WeldJointCode,   --焊口号
 | 
						||
jot.Specification,  --焊缝规格
 | 
						||
(CASE WHEN mat1.MaterialCode IS NOT NULL AND mat2.MaterialCode IS NOT NULL
 | 
						||
	  THEN mat1.MaterialCode + '/' + mat2.MaterialCode
 | 
						||
	  ELSE (ISNULL(mat1.MaterialCode,'') + ISNULL(mat2.MaterialCode,'')) END) AS MaterialCode,    --材质
 | 
						||
(CASE WHEN jot.BackingWelderId!=jot.CoverWelderId THEN backingWelder.WelderCode+'/'+coverWelder.WelderCode ELSE backingWelder.WelderCode END) AS WelderCode,--焊工号
 | 
						||
rate.DetectionRateCode AS DetectionRateCode,--检测比例
 | 
						||
PointBatchItem.AcceptLevel AS  AcceptLevel, --验收等级
 | 
						||
(case when PointBatchItem.IsWelderFirst=1 then '首三件' else '' end) as Remark,
 | 
						||
jot.HeartNo1,--炉批1号
 | 
						||
jot.HeartNo2,--炉批2号
 | 
						||
(case jot.IsHotProess when 1 then '是' else '否' end) as IsHotProessName--是否热处理
 | 
						||
FROM dbo.Batch_BatchTrustItem AS BatchTrustItem
 | 
						||
LEFT JOIN Batch_PointBatchItem AS PointBatchItem ON PointBatchItem.PointBatchItemId=BatchTrustItem.PointBatchItemId
 | 
						||
LEFT JOIN dbo.Batch_PointBatch point ON point.PointBatchId = PointBatchItem.PointBatchId
 | 
						||
LEFT JOIN dbo.Base_DetectionRate rate ON rate.DetectionRateId = point.DetectionRateId
 | 
						||
LEFT JOIN dbo.Pipeline_WeldJoint jot ON jot.WeldJointId = BatchTrustItem.WeldJointId
 | 
						||
LEFT JOIN dbo.Pipeline_Pipeline pipe ON pipe.PipelineId = jot.PipelineId
 | 
						||
LEFT JOIN dbo.Welder_Welder backingWelder ON backingWelder.WelderId = jot.BackingWelderId
 | 
						||
LEFT JOIN dbo.Welder_Welder coverWelder ON coverWelder.WelderId = jot.CoverWelderId
 | 
						||
LEFT JOIN Base_Material AS mat1 ON mat1.MaterialId = jot.Material1Id
 | 
						||
LEFT JOIN Base_Material AS mat2 ON mat2.MaterialId = jot.Material2Id
 | 
						||
WHERE BatchTrustItem.TrustBatchId=@TrustBatchId and BatchTrustItem.IsCancelTrust is null
 | 
						||
 | 
						||
GO
 | 
						||
------------------------------------已下已更新---------------------------------------------
 | 
						||
 | 
						||
ALTER TABLE dbo.Batch_BatchTrust ADD GrooveTypeId NVARCHAR(50) NULL
 | 
						||
ALTER TABLE dbo.Batch_BatchTrust ADD WeldingMethodId NVARCHAR(50) NULL
 | 
						||
ALTER TABLE dbo.Batch_BatchTrust ADD IsWelderFirst BIT  NULL
 | 
						||
GO
 | 
						||
 | 
						||
 | 
						||
ALTER VIEW [dbo].[View_GenerateTrust_FJ] 
 | 
						||
AS
 | 
						||
-------正常点口生成委托-----------
 | 
						||
SELECT point.ProjectId,point.InstallationId,pipe.WorkAreaId ,point.UnitId,pointItem.PointBatchId,
 | 
						||
       point.DetectionTypeId,point.PipelineId,jot.WeldingMethodId,jot.GrooveTypeId,
 | 
						||
	   (CASE WHEN pointItem.IsWelderFirst=1 THEN 1 ELSE 0 END) AS IsWelderFirst
 | 
						||
FROM dbo.Batch_PointBatchItem pointItem
 | 
						||
LEFT JOIN dbo.Batch_PointBatch point ON point.PointBatchId = pointItem.PointBatchId
 | 
						||
LEFT JOIN dbo.Batch_BatchTrustItem trustItem ON trustItem.PointBatchItemId = pointItem.PointBatchItemId
 | 
						||
LEFT JOIN dbo.Pipeline_Pipeline pipe ON pipe.PipelineId = point.PipelineId
 | 
						||
LEFT JOIN dbo.Pipeline_WeldJoint jot ON jot.WeldJointId = pointItem.WeldJointId
 | 
						||
WHERE  pointItem.CutDate IS NULL AND pointItem.PointDate IS NOT NULL 
 | 
						||
       AND  trustItem.TrustBatchItemId IS NULL 
 | 
						||
	   AND pointItem.PointState='1'
 | 
						||
	   AND pointItem.JLAudit<>'' AND pointItem.JLAudit IS NOT NULL 
 | 
						||
	   AND pointItem.GLGSAudit<>'' AND pointItem.GLGSAudit IS NOT NULL 
 | 
						||
GROUP BY point.ProjectId,point.InstallationId,pipe.WorkAreaId,point.UnitId,pointItem.PointBatchId,point.DetectionTypeId,
 | 
						||
         point.PipelineId,jot.WeldingMethodId,jot.GrooveTypeId,CASE WHEN pointItem.IsWelderFirst=1 THEN 1 ELSE 0 END
 | 
						||
 | 
						||
 | 
						||
 | 
						||
GO
 | 
						||
 | 
						||
 | 
						||
ALTER VIEW [dbo].[View_GenerateTrustItem_FJ] 
 | 
						||
AS
 | 
						||
SELECT point.ProjectId,point.InstallationId,pipe.WorkAreaId ,point.UnitId,point.DetectionTypeId,
 | 
						||
       point.PipelineId,jot.WeldingMethodId,jot.GrooveTypeId, 
 | 
						||
	   (CASE WHEN pointItem.IsWelderFirst=1 THEN 1 ELSE 0 END) AS IsWelderFirst,
 | 
						||
	   --上面是条件
 | 
						||
       rate.DetectionRateValue,pointItem.PointBatchItemId,pointItem.PointBatchId,pointItem.WeldJointId,jot.Dia
 | 
						||
FROM dbo.Batch_PointBatchItem pointItem
 | 
						||
LEFT JOIN dbo.Pipeline_WeldJoint jot ON jot.WeldJointId = pointItem.WeldJointId
 | 
						||
LEFT JOIN dbo.Batch_PointBatch point ON point.PointBatchId = pointItem.PointBatchId
 | 
						||
LEFT JOIN dbo.Batch_BatchTrustItem trustItem ON trustItem.PointBatchItemId = pointItem.PointBatchItemId
 | 
						||
LEFT JOIN dbo.Pipeline_Pipeline pipe ON pipe.PipelineId = point.PipelineId
 | 
						||
LEFT JOIN dbo.Base_DetectionRate rate ON rate.DetectionRateId = point.DetectionRateId
 | 
						||
WHERE  pointItem.CutDate IS NULL AND pointItem.PointDate IS NOT NULL 
 | 
						||
       AND pointItem.PointState='1'
 | 
						||
	   AND  trustItem.TrustBatchItemId IS NULL  
 | 
						||
	   AND pointItem.JLAudit<>'' AND pointItem.JLAudit IS NOT NULL 
 | 
						||
	   AND pointItem.GLGSAudit<>'' AND pointItem.GLGSAudit IS NOT NULL 
 | 
						||
 | 
						||
GO
 | 
						||
 | 
						||
 | 
						||
 | 
						||
ALTER VIEW [dbo].[View_Batch_BatchTrust]
 | 
						||
AS
 | 
						||
/********无损委托********/
 | 
						||
SELECT BatchTrust.TrustBatchId, 
 | 
						||
BatchTrust.TrustBatchCode, 
 | 
						||
(CASE WHEN BatchTrust.TrustType='1' THEN BatchTrust.TrustBatchCode 
 | 
						||
      WHEN BatchTrust.TrustType='2' THEN BatchTrust.TrustBatchCode+'K1'
 | 
						||
	  WHEN BatchTrust.TrustType='3' THEN BatchTrust.TrustBatchCode+'R1' END) AS NewTrustBatchCode,
 | 
						||
BatchTrust.TrustDate, 
 | 
						||
BatchTrust.NDEUuit,
 | 
						||
BatchTrust.ProjectId, 
 | 
						||
project.ProjectCode,
 | 
						||
BatchTrust.UnitId, 
 | 
						||
BatchTrust.InstallationId, 
 | 
						||
BatchTrust.PipelineId,
 | 
						||
pipe.PipelineCode,
 | 
						||
BatchTrust.DetectionTypeId,
 | 
						||
BatchTrust.IsCheck,
 | 
						||
BatchTrust.TopointBatch,
 | 
						||
BatchTrust.SurfaceState,
 | 
						||
BatchTrust.DetectionTiming,
 | 
						||
BatchTrust.QuaCertFile,
 | 
						||
BatchTrust.AcceptStandard,
 | 
						||
Unit.UnitCode,
 | 
						||
Unit.UnitName,
 | 
						||
Installation.InstallationName,
 | 
						||
Installation.InstallationCode,
 | 
						||
DetectionType.DetectionTypeCode,
 | 
						||
ndtCheck.TrustBatchId AS CheckTrustBatchId,
 | 
						||
DetectionType.TestStandard,
 | 
						||
DetectionType.TechLevel,
 | 
						||
rate.DetectionRateCode,
 | 
						||
groove.GrooveTypeCode,
 | 
						||
'巴斯夫一体化基地(广东)有限公司' AS TrustUnit,
 | 
						||
mat.WeldingMethodCode
 | 
						||
FROM Batch_BatchTrust AS BatchTrust
 | 
						||
LEFT JOIN dbo.Base_Project project ON project.ProjectId = BatchTrust.ProjectId
 | 
						||
LEFT JOIN Base_Unit AS Unit ON Unit.UnitId=BatchTrust.UnitId
 | 
						||
LEFT JOIN Project_Installation AS Installation ON Installation.InstallationId=BatchTrust.InstallationId
 | 
						||
LEFT JOIN dbo.Pipeline_Pipeline pipe ON pipe.PipelineId = BatchTrust.PipelineId
 | 
						||
LEFT JOIN Base_DetectionType AS DetectionType ON DetectionType.DetectionTypeId=BatchTrust.DetectionTypeId
 | 
						||
LEFT JOIN dbo.Base_DetectionRate rate ON rate.DetectionRateId=pipe.DetectionRateId
 | 
						||
LEFT JOIN dbo.Base_WeldingMethod mat ON mat.WeldingMethodId = BatchTrust.WeldingMethodId
 | 
						||
LEFT JOIN dbo.Base_GrooveType groove ON groove.GrooveTypeId = BatchTrust.GrooveTypeId
 | 
						||
LEFT JOIN dbo.Batch_NDE ndtCheck ON ndtCheck.TrustBatchId = BatchTrust.TrustBatchId
 | 
						||
WHERE (SELECT COUNT(TrustBatchItemId) FROM Batch_BatchTrustItem WHERE IsCancelTrust IS NULL AND TrustBatchId=BatchTrust.TrustBatchId)>0
 | 
						||
 | 
						||
 | 
						||
 | 
						||
 | 
						||
GO
 | 
						||
 | 
						||
 |