SGGL_SHJ/DataBase/版本日志/SGGLDB_V2023-12-01.sql

456 lines
22 KiB
Transact-SQL
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

ALTER VIEW [dbo].[View_HJGL_NoWeldJointFind]
AS
--灌보보왯꿴冷
SELECT jot.WeldJointId,
jot.WeldJointCode,
cast((case when charindex('/',jot.WeldJointCode)>0
then (case when ISNUMERIC(RIGHT(jot.WeldJointCode,CHARINDEX('/',REVERSE(jot.WeldJointCode))-1))=1 then RIGHT(jot.WeldJointCode,CHARINDEX('/',REVERSE(jot.WeldJointCode))-1) else '1000' end)
else '1000' end) as int) as WeldJointNum,
jot.PipelineId,
jot.WeldingDailyId,
jot.JointAttribute,
jot.Dia,
jot.DNDia,
jot.Size,
jot.Thickness,
jot.Remark,
WeldType.WeldTypeCode,
method.WeldingMethodCode,
rod.ConsumablesCode AS WeldingRodCode,
wire.ConsumablesCode AS WeldingWireCode,
mat1.MaterialCode AS Material1Code ,
mat2.MaterialCode AS Material2Code
FROM dbo.HJGL_WeldJoint jot
LEFT JOIN dbo.HJGL_PreWeldingDaily pre ON pre.WeldJointId = jot.WeldJointId
LEFT JOIN Base_WeldType AS WeldType ON WeldType.WeldTypeId=jot.WeldTypeId
LEFT JOIN Base_WeldingMethod AS method ON method.WeldingMethodId=jot.WeldingMethodId
LEFT JOIN Base_Material AS mat1 ON mat1.MaterialId = jot.Material1Id
LEFT JOIN Base_Material AS mat2 ON mat2.MaterialId = jot.Material2Id
LEFT JOIN Base_Consumables AS wire ON wire.ConsumablesId=jot.WeldingWire
LEFT JOIN Base_Consumables AS rod ON rod.ConsumablesId=jot.WeldingRod
WHERE pre.PreWeldingDailyId IS NULL
and jot.WeldJointId not in (select WeldJointId from HJGL_WeldJoint where IsTwoJoint = 1 and (AuditDate is null or AuditDate=''))
GO
ALTER VIEW [dbo].[View_HJGL_WeldJoint]
AS
SELECT jot.[ProjectId] --淃커Id
,pipe.[UnitWorkId] --데貫묏넋Id
,uw.UnitWorkName --데貫묏넋
,pipe.[UnitId] --데貫Id
,unit.UnitName --데貫
,jot.[PipelineCode] --밗窟뵀
,pipe.[SingleNumber] --데窟暠뵀
,pipe.[SingleName] --暠笭츰냔
,pipe.[MediumId] --썽醴Id
,medium.MediumCode
,medium.MediumName --썽醴츰냔
,pipe.[PipingClassId] --밗돛된섬Id
,pipingClass.PipingClassCode --밗돛된섬
,pipe.[DetectionRateId] --決<>궐절Id
,dr.DetectionRateCode --決<>궐절절흔51020
,pipe.DetectionType --決<>잚謹Id(옵콘뜩몸,櫓쇌痰|롸몰)
,STUFF((SELECT ',' + DetectionTypeCode FROM Base_DetectionType
WHERE CHARINDEX('|'+LTRIM(DetectionTypeId)+'|','|'+ pipe.DetectionType + '|') > 0 FOR XML PATH('') ), 1, 1, '') AS DetectionTypeStr --決<>잚謹옵콘뜩몸櫓쇌痰,롸몰)
,pipe.DesignTemperature --<2D>셕侊똑→
,pipe.DesignPress --<2D>셕箕제Mpa(g)
,pipe.TestMedium --箕제桿駱썽醴Id
,tm.MediumName AS TestMediumName --箕제桿駱썽醴
,pipe.TestPressure --箕제桿駱箕제Mpa(g)
,pipe.PressurePipingClassId --箕제밗돛섬깎Id
,ppc.PressurePipingClassCode --箕제밗돛섬깎
,pipe.PipeLenth --밗窟낀똑(m)
,pipe.LeakMedium --橘쨋昑桿駱썽醴Id
,tm2.MediumName AS LeakMediumName --橘쨋昑桿駱썽醴
,pipe.LeakPressure --橘쨋昑桿駱箕제Mpa(g)
,pipe.PCMedium --뉘求狼헹Id
,pm.PurgeMethodCode --뉘求狼헹
,pipe.VacuumPressure --廬왕桿駱箕제Kpa(a)
,pipe.MaterialId --꼼醴Id
,mat.MaterialCode AS PipeMaterialCode --꼼醴
,pipe.Remark AS PipeRemark --구鬧
,pipe.FlowingSection as FlowingSection --직彊뙈
,jot.[WeldJointId] --보왯Id
,jot.[WeldJointCode] --보왯뵀
,jot.[Material1Id] --꼼醴1Id
,mat1.MaterialCode AS Material1Code --꼼醴1
,jot.[Material2Id] --꼼醴2Id
,mat2.MaterialCode AS Material2Code --꼼醴2
,jot.[Dia] --棍쓺
,jot.DNDia --DN무냔殮쓺
,jot.[Size] --댐凜
,jot.[Thickness] --귿비
,jot.[Specification] --방목
,jot.[WeldTypeId] --보룹잚謹Id
,WeldType.WeldTypeCode --보룹잚謹
,jot.[DetectionTypeId] --쇱꿎잚謹Id
,ndt.DetectionTypeCode --쇱꿎잚謹
,jot.[Components1Id] --莉숭1뵀Id
,com1.ComponentsCode AS ComponentsCode1 --莉숭1뵀
,jot.[Components2Id] --莉숭2뵀Id
,com2.ComponentsCode AS ComponentsCode2 --莉숭2뵀
,jot.DesignIsHotProess --角뤠훑뇹잿
,CASE jot.DesignIsHotProess WHEN 1 THEN '' ELSE '' END AS DesignIsHotProessStr --角뤠훑뇹잿
,jot.[WeldingMethodId] --보쌈렘랬Id
,WeldingMethod.WeldingMethodCode --보쌈렘랬
,jot.WPQId --WPS돨Id
,wps.WPQCode --WPS긍뵀
,jot.[GrooveTypeId] --팃왯잚謹Id
,GrooveType.GrooveTypeCode --팃왯잚謹
,jot.[WeldingRod] --보係Id
,rod.ConsumablesCode AS WeldingRodCode --보係
,jot.[WeldingWire] --보介Id
,wire.ConsumablesCode AS WeldingWireCode --보介
,jot.PreTemperature --渡훑侊똑
,jot.[JointAttribute] --보왯橄昑
,jot.TwoJointType --랗늴보왯劤藤잚謹
,pipe.PipeArea --묏낍渡齡/君끝갛陋
,daily.WeldingDate as WeldingDateD
,CONVERT(VARCHAR(100), daily.WeldingDate, 23) AS WeldingDate --보쌈휑퍅
,BackingWelder.WelderCode AS BackingWelderCode --댔뒀보묏
,CoverWelder.WelderCode AS CoverWelderCode --맨충보묏
,(CASE (SELECT COUNT(*) FROM [dbo].[HJGL_HotProess_TrustItem] hpti
WHERE hpti.WeldJointId=jot.WeldJointId) WHEN 0 THEN '' ELSE (SELECT TOP 1 ISNULL(ReportNo,'') FROM [dbo].[HJGL_HotProess_Trust] hpt
LEFT JOIN [dbo].[HJGL_HotProess_TrustItem] hpti ON hpti.HotProessTrustId=hpt.HotProessTrustId
WHERE hpti.WeldJointId=jot.WeldJointId) END) AS HotProessReportNo --훑뇹잿괩멩긍뵀
,(CASE (SELECT TOP 1 IsCompleted FROM [dbo].[HJGL_HotProess_TrustItem] hpti
WHERE hpti.WeldJointId=jot.WeldJointId) WHEN 1 THEN '供냥' WHEN 0 THEN '灌供냥' ELSE '灌훑뇹잿' END) AS HotProessResult --훑뇹잿쇱꿎써벎
,(CASE (SELECT COUNT(*) FROM [dbo].HJGL_Hard_TrustItem hti
WHERE hti.WeldJointId=jot.WeldJointId) WHEN 0 THEN '' ELSE (SELECT TOP 1 ISNULL(InspectionNum,'') FROM [dbo].HJGL_Hard_Trust ht
LEFT JOIN [dbo].HJGL_Hard_TrustItem hti ON hti.HardTrustID=ht.HardTrustID
WHERE hti.WeldJointId=jot.WeldJointId) END) AS HardReportNo --袒똑괩멩긍뵀
,(CASE (SELECT TOP 1 IsPass FROM [dbo].HJGL_Hard_TrustItem hti
WHERE hti.WeldJointId=jot.WeldJointId) WHEN 1 THEN '북목' WHEN 0 THEN '꼇북목' ELSE '덤쇱꿎' END) AS HardResult --袒똑쇱꿎써벎
,(CASE (SELECT COUNT(*) FROM [dbo].HJGL_Batch_BatchTrustItem bti
WHERE bti.WeldJointId=jot.WeldJointId) WHEN 0 THEN '' ELSE (SELECT TOP 1 TrustBatchCode FROM [dbo].HJGL_Batch_BatchTrust bt
LEFT JOIN [dbo].HJGL_Batch_BatchTrustItem bti ON bti.TrustBatchId=bt.TrustBatchId
WHERE bti.WeldJointId=jot.WeldJointId) END) AS TrustBatchCode --官辜데긍뵀
,(CASE (SELECT COUNT(*) FROM [dbo].HJGL_Batch_NDEItem ndei
LEFT JOIN [dbo].HJGL_Batch_BatchTrustItem bti ON bti.TrustBatchItemId=ndei.TrustBatchItemId
WHERE bti.WeldJointId=jot.WeldJointId) WHEN 0 THEN '' ELSE (SELECT TOP 1 ISNULL(NDECode,'') FROM [dbo].HJGL_Batch_NDE nde
LEFT JOIN [dbo].HJGL_Batch_NDEItem ndei ON ndei.NDEID=nde.NDEID
LEFT JOIN [dbo].HJGL_Batch_BatchTrustItem bti ON bti.TrustBatchItemId=ndei.TrustBatchItemId
WHERE bti.WeldJointId=jot.WeldJointId) END) AS NDECode --쇱꿎데긍뵀
,(CASE (SELECT TOP 1 CheckResult FROM [dbo].HJGL_Batch_NDEItem ndei
LEFT JOIN [dbo].HJGL_Batch_BatchTrustItem bti ON bti.TrustBatchItemId=ndei.TrustBatchItemId
WHERE bti.WeldJointId=jot.WeldJointId) WHEN '1' THEN '북목' WHEN '2' THEN '꼇북목' ELSE '' END) AS CheckResult --쇱꿎써벎
,jot.PipelineId
,jot.[JointArea]
,jot.[WeldingLocationId]
,jot.[HeartNo1]
,jot.[HeartNo2]
,jot.[IsHotProess]
,jot.[WeldingDailyId]
,jot.[BackingWelderId]
,jot.[CoverWelderId]
,jot.WeldingMode
,jot.Remark
,jot.IsTwoJoint
,jot.SubmitMan
,jot.AuditMan
,jot.AuditMan2
,jot.AuditDate
,jot.AuditDate2
,WeldingLocation.WeldingLocationCode
,CASE WHEN jot.WeldingDailyId IS NULL THEN '' ELSE '' END AS IsWelding
,CASE WHEN jot.WeldingDailyId IS NULL THEN '灌供냥' ELSE '綠供냥' END AS IsWeldOK
,CASE WHEN jot.IsHotProess=1 THEN '' ELSE '' END AS IsHotProessStr,
BackingWelder.PersonName AS BackingWelderName,
CoverWelder.PersonName AS CoverWelderName,
(CASE WHEN CoverWelder.WelderCode IS NOT NULL AND BackingWelder.WelderCode IS NOT NULL
THEN CoverWelder.WelderCode + '/' + BackingWelder.WelderCode
ELSE (ISNULL(CoverWelder.WelderCode,'') + ISNULL(BackingWelder.WelderCode,'')) END) AS WelderCode, --보묏
(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, --꼼醴
daily.WeldingDailyCode,
pointItem.PointBatchId,
point.PointBatchCode,
(CASE WHEN pointItem.PointState='1' THEN '綠듐왯' WHEN pointItem.PointState='2' THEN '綠윈拷' ELSE '' END) AS IsPoint
FROM [dbo].[HJGL_WeldJoint] jot
LEFT JOIN dbo.HJGL_Pipeline pipe ON pipe.PipelineId=jot.PipelineId
LEFT JOIN dbo.WBS_UnitWork uw ON uw.UnitWorkId=pipe.UnitWorkId
LEFT JOIN dbo.Base_Unit unit ON unit.UnitId=pipe.UnitId
LEFT JOIN Base_WeldType AS WeldType ON WeldType.WeldTypeId=jot.WeldTypeId
LEFT JOIN dbo.Base_DetectionRate dr ON dr.DetectionRateId = pipe.DetectionRateId
LEFT JOIN Base_TestMedium tm ON tm.TestMediumId=pipe.TestMedium
LEFT JOIN Base_TestMedium tm2 ON tm2.TestMediumId=pipe.LeakMedium
LEFT JOIN Base_PurgeMethod pm ON pm.PurgeMethodId=pipe.PCMedium
LEFT JOIN Base_PressurePipingClass ppc ON ppc.PressurePipingClassId=pipe.PressurePipingClassId
LEFT JOIN Base_Material AS mat ON mat.MaterialId = pipe.MaterialId
LEFT JOIN Base_Material AS mat1 ON mat1.MaterialId = jot.Material1Id
LEFT JOIN Base_Material AS mat2 ON mat2.MaterialId = jot.Material2Id
LEFT JOIN Base_WeldingMethod AS WeldingMethod ON WeldingMethod.WeldingMethodId=jot.WeldingMethodId
LEFT JOIN Base_WeldingLocation AS WeldingLocation ON WeldingLocation.WeldingLocationId=jot.WeldingLocationId
LEFT JOIN Base_Consumables AS wire ON wire.ConsumablesId=jot.WeldingWire
LEFT JOIN Base_Consumables AS rod ON rod.ConsumablesId=jot.WeldingRod
LEFT JOIN Base_GrooveType AS GrooveType ON GrooveType.GrooveTypeId=jot.GrooveTypeId
LEFT JOIN Base_Components AS com1 ON com1.ComponentsId = jot.Components1Id
LEFT JOIN Base_Components AS com2 ON com2.ComponentsId = jot.Components2Id
LEFT JOIN SitePerson_Person AS BackingWelder ON BackingWelder.PersonId=jot.BackingWelderId and BackingWelder.ProjectId=jot.ProjectId
LEFT JOIN SitePerson_Person AS CoverWelder ON CoverWelder.PersonId=jot.CoverWelderId and CoverWelder.ProjectId=jot.ProjectId
LEFT JOIN dbo.HJGL_WeldingDaily AS daily ON daily.WeldingDailyId=jot.WeldingDailyId
LEFT JOIN Base_PipingClass AS pipingClass ON pipingClass.PipingClassId=pipe.PipingClassId
LEFT JOIN dbo.Base_Medium medium ON medium.MediumId = pipe.MediumId
LEFT JOIN dbo.Base_DetectionType ndt ON ndt.DetectionTypeId = jot.DetectionTypeId
LEFT JOIN dbo.WPQ_WPQList wps ON wps.WPQId = jot.WPQId
LEFT JOIN dbo.HJGL_Batch_PointBatchItem pointItem ON pointItem.WeldJointId = jot.WeldJointId
LEFT JOIN dbo.HJGL_Batch_PointBatch point ON point.PointBatchId = pointItem.PointBatchId
GO
ALTER VIEW [dbo].[View_HJGL_Pipeline]
AS
/*************밗窟柬暠*****************/
SELECT pipeline.PipelineId,
pipeline.ProjectId,
pipeline.UnitId,
pipeline.UnitWorkId,
pipeline.PipelineCode,
pipeline.SingleName,
pipeline.SingleNumber,
pipeline.PipingClassId,
pipeline.MediumId,
pipingClass.PipingClassCode,
pipeline.DetectionRateId,
rate.DetectionRateCode,
pipeline.DetectionType,
pipeline.TestPressure,
pipeline.TestMedium,
pipeline.PressurePipingClassId,
pc.PressurePipingClassCode,
pipeline.PipeLenth,
pipeline.DesignPress,
pipeline.DesignTemperature,
pipeline.Remark,
pipeline.LeakPressure,
pipeline.LeakMedium,
pipeline.VacuumPressure,
pipeline.PCMedium ,
pipeline.PCtype,
pipeline.MaterialId,
pipeline.PipeArea,
pipeline.FlowingSection,
mat.MaterialCode,
lea.MediumName AS LeakMediumName,
pur.PurgeMethodName AS PCMediumName,
CAST((SELECT SUM(ISNULL(Size,0)) FROM dbo.HJGL_WeldJoint WHERE PipelineId=pipeline.PipelineId) AS DECIMAL(8,3)) AS TotalDin,
CAST((SELECT ISNULL(SUM(ISNULL(jot.Size,0)),0) FROM dbo.HJGL_WeldJoint jot WHERE jot.PipelineId=pipeline.PipelineId AND jot.WeldingDailyId IS NOT NULL) AS DECIMAL(8,3)) AS FinishSize,
(SELECT COUNT(WeldJointId) FROM dbo.HJGL_WeldJoint WHERE PipelineId=pipeline.PipelineId and IsTwoJoint is null) AS JointCount,
(SELECT COUNT(WeldJointId) FROM dbo.HJGL_WeldJoint WHERE PipelineId=pipeline.PipelineId and IsTwoJoint is null and WeldingDailyId IS NOT NULL) AS FinishJointCount,
unit.UnitName,
workArea.UnitWorkCode,
medium.MediumCode,
medium.MediumName AS MediumName,
testMedium.MediumCode AS TestMediumCode,
pipeline.ActEndDate AS FinishedDate,
pipeline.IsFinished
FROM dbo.HJGL_Pipeline AS pipeline
LEFT JOIN Base_PipingClass AS pipingClass ON pipingClass.PipingClassId=pipeline.PipingClassId
LEFT JOIN dbo.Base_Unit AS unit ON unit.UnitId=pipeline.UnitId
LEFT JOIN WBS_UnitWork AS workArea ON workArea.UnitWorkId=pipeline.UnitWorkId
LEFT JOIN Base_Medium AS medium ON medium.MediumId=pipeline.MediumId
LEFT JOIN dbo.Base_TestMedium AS testMedium ON testMedium.TestMediumId=pipeline.TestMedium
LEFT JOIN dbo.Base_DetectionRate rate ON rate.DetectionRateId = pipeline.DetectionRateId
LEFT JOIN dbo.Base_PressurePipingClass pc ON pc.PressurePipingClassId = pipeline.PressurePipingClassId
LEFT JOIN dbo.Base_TestMedium AS lea ON lea.TestMediumId=pipeline.LeakMedium
LEFT JOIN dbo.Base_PurgeMethod AS pur ON pur.PurgeMethodId=pipeline.PCMedium
LEFT JOIN dbo.Base_Material AS mat ON mat.MaterialId=pipeline.MaterialId
GO
ALTER VIEW [dbo].[View_HJGL_WeldJoint]
AS
SELECT jot.[ProjectId] --淃커Id
,pipe.[UnitWorkId] --데貫묏넋Id
,uw.UnitWorkName --데貫묏넋
,pipe.[UnitId] --데貫Id
,unit.UnitName --데貫
,jot.[PipelineCode] --밗窟뵀
,pipe.[SingleNumber] --데窟暠뵀
,pipe.[SingleName] --暠笭츰냔
,pipe.[MediumId] --썽醴Id
,medium.MediumCode
,medium.MediumName --썽醴츰냔
,pipe.[PipingClassId] --밗돛된섬Id
,pipingClass.PipingClassCode --밗돛된섬
,pipe.[DetectionRateId] --決<>궐절Id
,dr.DetectionRateCode --決<>궐절절흔51020
,pipe.DetectionType --決<>잚謹Id(옵콘뜩몸,櫓쇌痰|롸몰)
,STUFF((SELECT ',' + DetectionTypeCode FROM Base_DetectionType
WHERE CHARINDEX('|'+LTRIM(DetectionTypeId)+'|','|'+ pipe.DetectionType + '|') > 0 FOR XML PATH('') ), 1, 1, '') AS DetectionTypeStr --決<>잚謹옵콘뜩몸櫓쇌痰,롸몰)
,pipe.DesignTemperature --<2D>셕侊똑→
,pipe.DesignPress --<2D>셕箕제Mpa(g)
,pipe.TestMedium --箕제桿駱썽醴Id
,tm.MediumName AS TestMediumName --箕제桿駱썽醴
,pipe.TestPressure --箕제桿駱箕제Mpa(g)
,pipe.PressurePipingClassId --箕제밗돛섬깎Id
,ppc.PressurePipingClassCode --箕제밗돛섬깎
,pipe.PipeLenth --밗窟낀똑(m)
,pipe.LeakMedium --橘쨋昑桿駱썽醴Id
,tm2.MediumName AS LeakMediumName --橘쨋昑桿駱썽醴
,pipe.LeakPressure --橘쨋昑桿駱箕제Mpa(g)
,pipe.PCMedium --뉘求狼헹Id
,pm.PurgeMethodCode --뉘求狼헹
,pipe.VacuumPressure --廬왕桿駱箕제Kpa(a)
,pipe.MaterialId --꼼醴Id
,mat.MaterialCode AS PipeMaterialCode --꼼醴
,pipe.Remark AS PipeRemark --구鬧
,pipe.FlowingSection as FlowingSection --직彊뙈
,jot.[WeldJointId] --보왯Id
,jot.[WeldJointCode] --보왯뵀
,jot.[Material1Id] --꼼醴1Id
,mat1.MaterialCode AS Material1Code --꼼醴1
,jot.[Material2Id] --꼼醴2Id
,mat2.MaterialCode AS Material2Code --꼼醴2
,jot.[Dia] --棍쓺
,jot.DNDia --DN무냔殮쓺
,jot.[Size] --댐凜
,jot.[Thickness] --귿비
,jot.[Specification] --방목
,jot.[WeldTypeId] --보룹잚謹Id
,WeldType.WeldTypeCode --보룹잚謹
,jot.[DetectionTypeId] --쇱꿎잚謹Id
,ndt.DetectionTypeCode --쇱꿎잚謹
,jot.[Components1Id] --莉숭1뵀Id
,com1.ComponentsCode AS ComponentsCode1 --莉숭1뵀
,jot.[Components2Id] --莉숭2뵀Id
,com2.ComponentsCode AS ComponentsCode2 --莉숭2뵀
,jot.DesignIsHotProess --角뤠훑뇹잿
,CASE jot.DesignIsHotProess WHEN 1 THEN '' ELSE '' END AS DesignIsHotProessStr --角뤠훑뇹잿
,jot.[WeldingMethodId] --보쌈렘랬Id
,WeldingMethod.WeldingMethodCode --보쌈렘랬
,jot.WPQId --WPS돨Id
,wps.WPQCode --WPS긍뵀
,jot.[GrooveTypeId] --팃왯잚謹Id
,GrooveType.GrooveTypeCode --팃왯잚謹
,jot.[WeldingRod] --보係Id
,rod.ConsumablesCode AS WeldingRodCode --보係
,jot.[WeldingWire] --보介Id
,wire.ConsumablesCode AS WeldingWireCode --보介
,jot.PreTemperature --渡훑侊똑
,jot.[JointAttribute] --보왯橄昑
,jot.TwoJointType --랗늴보왯劤藤잚謹
,pipe.PipeArea --묏낍渡齡/君끝갛陋
,daily.WeldingDate as WeldingDateD
,CONVERT(VARCHAR(100), daily.WeldingDate, 23) AS WeldingDate --보쌈휑퍅
,BackingWelder.WelderCode AS BackingWelderCode --댔뒀보묏
,CoverWelder.WelderCode AS CoverWelderCode --맨충보묏
,(CASE (SELECT COUNT(*) FROM [dbo].[HJGL_HotProess_TrustItem] hpti
WHERE hpti.WeldJointId=jot.WeldJointId) WHEN 0 THEN '' ELSE (SELECT TOP 1 ISNULL(ReportNo,'') FROM [dbo].[HJGL_HotProess_Trust] hpt
LEFT JOIN [dbo].[HJGL_HotProess_TrustItem] hpti ON hpti.HotProessTrustId=hpt.HotProessTrustId
WHERE hpti.WeldJointId=jot.WeldJointId) END) AS HotProessReportNo --훑뇹잿괩멩긍뵀
,(CASE (SELECT TOP 1 IsCompleted FROM [dbo].[HJGL_HotProess_TrustItem] hpti
WHERE hpti.WeldJointId=jot.WeldJointId) WHEN 1 THEN '供냥' WHEN 0 THEN '灌供냥' ELSE '灌훑뇹잿' END) AS HotProessResult --훑뇹잿쇱꿎써벎
,(CASE (SELECT COUNT(*) FROM [dbo].HJGL_Hard_TrustItem hti
WHERE hti.WeldJointId=jot.WeldJointId) WHEN 0 THEN '' ELSE (SELECT TOP 1 ISNULL(InspectionNum,'') FROM [dbo].HJGL_Hard_Trust ht
LEFT JOIN [dbo].HJGL_Hard_TrustItem hti ON hti.HardTrustID=ht.HardTrustID
WHERE hti.WeldJointId=jot.WeldJointId) END) AS HardReportNo --袒똑괩멩긍뵀
,(CASE (SELECT TOP 1 IsPass FROM [dbo].HJGL_Hard_TrustItem hti
WHERE hti.WeldJointId=jot.WeldJointId) WHEN 1 THEN '북목' WHEN 0 THEN '꼇북목' ELSE '덤쇱꿎' END) AS HardResult --袒똑쇱꿎써벎
,(CASE (SELECT COUNT(*) FROM [dbo].HJGL_Batch_BatchTrustItem bti
WHERE bti.WeldJointId=jot.WeldJointId) WHEN 0 THEN '' ELSE (SELECT TOP 1 TrustBatchCode FROM [dbo].HJGL_Batch_BatchTrust bt
LEFT JOIN [dbo].HJGL_Batch_BatchTrustItem bti ON bti.TrustBatchId=bt.TrustBatchId
WHERE bti.WeldJointId=jot.WeldJointId) END) AS TrustBatchCode --官辜데긍뵀
,(CASE (SELECT COUNT(*) FROM [dbo].HJGL_Batch_NDEItem ndei
LEFT JOIN [dbo].HJGL_Batch_BatchTrustItem bti ON bti.TrustBatchItemId=ndei.TrustBatchItemId
WHERE bti.WeldJointId=jot.WeldJointId) WHEN 0 THEN '' ELSE (SELECT TOP 1 ISNULL(NDECode,'') FROM [dbo].HJGL_Batch_NDE nde
LEFT JOIN [dbo].HJGL_Batch_NDEItem ndei ON ndei.NDEID=nde.NDEID
LEFT JOIN [dbo].HJGL_Batch_BatchTrustItem bti ON bti.TrustBatchItemId=ndei.TrustBatchItemId
WHERE bti.WeldJointId=jot.WeldJointId) END) AS NDECode --쇱꿎데긍뵀
,(CASE (SELECT TOP 1 CheckResult FROM [dbo].HJGL_Batch_NDEItem ndei
LEFT JOIN [dbo].HJGL_Batch_BatchTrustItem bti ON bti.TrustBatchItemId=ndei.TrustBatchItemId
WHERE bti.WeldJointId=jot.WeldJointId) WHEN '1' THEN '북목' WHEN '2' THEN '꼇북목' ELSE '' END) AS CheckResult --쇱꿎써벎
,jot.PipelineId
,jot.[JointArea]
,jot.[WeldingLocationId]
,jot.[HeartNo1]
,jot.[HeartNo2]
,jot.[IsHotProess]
,jot.[WeldingDailyId]
,jot.[BackingWelderId]
,jot.[CoverWelderId]
,jot.WeldingMode
,jot.Remark
,jot.IsTwoJoint
,jot.SubmitMan
,jot.AuditMan
,jot.AuditMan2
,jot.AuditDate
,jot.AuditDate2
,WeldingLocation.WeldingLocationCode
,CASE WHEN jot.WeldingDailyId IS NULL THEN '' ELSE '' END AS IsWelding
,CASE WHEN jot.WeldingDailyId IS NULL THEN '灌供냥' ELSE '綠供냥' END AS IsWeldOK
,CASE WHEN jot.IsHotProess=1 THEN '' ELSE '' END AS IsHotProessStr,
BackingWelder.PersonName AS BackingWelderName,
CoverWelder.PersonName AS CoverWelderName,
(CASE WHEN CoverWelder.WelderCode IS NOT NULL AND BackingWelder.WelderCode IS NOT NULL
THEN CoverWelder.WelderCode + '/' + BackingWelder.WelderCode
ELSE (ISNULL(CoverWelder.WelderCode,'') + ISNULL(BackingWelder.WelderCode,'')) END) AS WelderCode, --보묏
(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, --꼼醴
daily.WeldingDailyCode,
pointItem.PointBatchId,
point.PointBatchCode,
(CASE WHEN pointItem.PointState='1' THEN '綠듐왯' WHEN pointItem.PointState='2' THEN '綠윈拷' ELSE '' END) AS IsPoint
FROM [dbo].[HJGL_WeldJoint] jot
LEFT JOIN dbo.HJGL_Pipeline pipe ON pipe.PipelineId=jot.PipelineId
LEFT JOIN dbo.WBS_UnitWork uw ON uw.UnitWorkId=pipe.UnitWorkId
LEFT JOIN dbo.HJGL_WeldingDaily AS daily ON daily.WeldingDailyId=jot.WeldingDailyId
LEFT JOIN dbo.Base_Unit unit ON unit.UnitId=daily.UnitId
LEFT JOIN Base_WeldType AS WeldType ON WeldType.WeldTypeId=jot.WeldTypeId
LEFT JOIN dbo.Base_DetectionRate dr ON dr.DetectionRateId = pipe.DetectionRateId
LEFT JOIN Base_TestMedium tm ON tm.TestMediumId=pipe.TestMedium
LEFT JOIN Base_TestMedium tm2 ON tm2.TestMediumId=pipe.LeakMedium
LEFT JOIN Base_PurgeMethod pm ON pm.PurgeMethodId=pipe.PCMedium
LEFT JOIN Base_PressurePipingClass ppc ON ppc.PressurePipingClassId=pipe.PressurePipingClassId
LEFT JOIN Base_Material AS mat ON mat.MaterialId = pipe.MaterialId
LEFT JOIN Base_Material AS mat1 ON mat1.MaterialId = jot.Material1Id
LEFT JOIN Base_Material AS mat2 ON mat2.MaterialId = jot.Material2Id
LEFT JOIN Base_WeldingMethod AS WeldingMethod ON WeldingMethod.WeldingMethodId=jot.WeldingMethodId
LEFT JOIN Base_WeldingLocation AS WeldingLocation ON WeldingLocation.WeldingLocationId=jot.WeldingLocationId
LEFT JOIN Base_Consumables AS wire ON wire.ConsumablesId=jot.WeldingWire
LEFT JOIN Base_Consumables AS rod ON rod.ConsumablesId=jot.WeldingRod
LEFT JOIN Base_GrooveType AS GrooveType ON GrooveType.GrooveTypeId=jot.GrooveTypeId
LEFT JOIN Base_Components AS com1 ON com1.ComponentsId = jot.Components1Id
LEFT JOIN Base_Components AS com2 ON com2.ComponentsId = jot.Components2Id
LEFT JOIN SitePerson_Person AS BackingWelder ON BackingWelder.PersonId=jot.BackingWelderId and BackingWelder.ProjectId=jot.ProjectId
LEFT JOIN SitePerson_Person AS CoverWelder ON CoverWelder.PersonId=jot.CoverWelderId and CoverWelder.ProjectId=jot.ProjectId
LEFT JOIN Base_PipingClass AS pipingClass ON pipingClass.PipingClassId=pipe.PipingClassId
LEFT JOIN dbo.Base_Medium medium ON medium.MediumId = pipe.MediumId
LEFT JOIN dbo.Base_DetectionType ndt ON ndt.DetectionTypeId = jot.DetectionTypeId
LEFT JOIN dbo.WPQ_WPQList wps ON wps.WPQId = jot.WPQId
LEFT JOIN dbo.HJGL_Batch_PointBatchItem pointItem ON pointItem.WeldJointId = jot.WeldJointId
LEFT JOIN dbo.HJGL_Batch_PointBatch point ON point.PointBatchId = pointItem.PointBatchId
GO