zoukankan      html  css  js  c++  java
  • 存储过程

    USE [ChangHong_612]
    GO
    /****** Object: StoredProcedure [dbo].[st_MES_CheckInspect] Script Date: 09/28/2015 09:25:42 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:cj
    -- Create date: 20130710
    -- Description: 检验结果
    -- st_MES_CheckInspect 'MS-OQC-SL2-2015-09-001',''
    -- =============================================
    ALTER PROCEDURE [dbo].[st_MES_CheckInspect] (
    @BillNo varchar(50),
    @CheckMan varchar(20)
    )
    AS
    BEGIN

    declare @checktype int
    select @checktype=checktype from MES_Inspect where billno=@BillNo
    if (@checktype=1)
    begin
    update i set checkresult=case when (Appearance='OK' or Appearance='') and Structure='OK' and ([Assembly]='OK' or [Assembly]='')
    and (PerformanceTest3='OK' or PerformanceTest3='') and (PerformanceTest2='OK' or PerformanceTest2='')
    and (PerformanceTest4='OK' or PerformanceTest4='') and (PerformanceTest8='OK' or PerformanceTest8='') and DeformationResult='OK' and GaugeResult='OK'
    then 'OK' else 'NG' end from MES_Inspect i join (select c.billno, Appearance,Structure,[Assembly],PerformanceTest3,PerformanceTest2,PerformanceTest4,PerformanceTest8,
    case when (isnull(g.LongUpDeformationResult,'OK')='OK') and isnull(g.LongMiddleDeformationResult,'OK')='OK'
    and isnull(g.LongDownDeformationResult,'OK')='OK' and isnull(g.WidthUpDeformationResult,'OK')='OK'
    and isnull(g.WidthMiddleDeformationResult,'OK')='OK' and isnull(g.WidthDownDeformationResult,'OK')='OK' then 'OK' else 'NG' end DeformationResult
    ,case when isnull(g.LongUpGaugeResult,'OK')='OK' and isnull(g.LongMiddleGaugeResult,'OK')='OK' and isnull(g.LongDownGaugeResult,'OK')='OK' and isnull(g.WidthUpGaugeResult,'OK')='OK'
    and isnull(g.WidthMiddleGaugeResult,'OK')='OK' and isnull(g.WidthDownGaugeResult,'OK')='OK' and isnull(g.WeightResult,'OK')='OK' then 'OK' else 'NG' end GaugeResult from MES_Inspect c
    left join
    (select billno,
    max(CASE ItemCode WHEN '1' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Appearance',
    max(CASE ItemCode WHEN '2' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Structure',
    max(CASE ItemCode WHEN '3' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Assembly',
    max(CASE ItemCode WHEN '6' THEN case when ItemValue='不合格' then 'NG' else 'OK' end END) AS 'PerformanceTest3',
    max(CASE ItemCode WHEN '5' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'PerformanceTest2',
    max(CASE ItemCode WHEN '7' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'PerformanceTest4',
    max(CASE ItemCode WHEN '8' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'PerformanceTest8'
    from MES_InspectSingle group by billno) s on c.BillNO=s.BillNO left join
    (select billno,
    max(CASE when ItemType=3 and ItemCode='上长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongUpGaugeResult',
    max(CASE when ItemType=3 and ItemCode='中长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongMiddleGaugeResult',
    max(CASE when ItemType=3 and ItemCode='下长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongDownGaugeResult',
    max(CASE when ItemType=3 and ItemCode='左宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthUpGaugeResult',
    max(CASE when ItemType=3 and ItemCode='中宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthMiddleGaugeResult',
    max(CASE when ItemType=3 and ItemCode='右宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthDownGaugeResult',
    max(CASE when ItemType=5 and ItemCode='上长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongUpDeformationResult',
    max(CASE when ItemType=5 and ItemCode='中长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongMiddleDeformationResult',
    max(CASE when ItemType=5 and ItemCode='下长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongDownDeformationResult',
    max(CASE when ItemType=5 and ItemCode='左宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthUpDeformationResult',
    max(CASE when ItemType=5 and ItemCode='中宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthMiddleDeformationResult',
    max(CASE when ItemType=5 and ItemCode='右宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthDownDeformationResult',
    max(CASE when ItemType=1 and ItemCode='重量' and Position='重量' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WeightResult'
    from MES_InspectGauge group by billno) g on g.BillNO=s.BillNO where checktype=1) a on i.billno=a.billno where i.billno=@BillNo
    end
    else if (@checktype=2)
    begin
    update i set checkresult=case when (Appearance='OK' or Appearance='') and Structure='OK' and ([Assembly]='OK' or [Assembly]='') and (Packing='OK' or Packing='')
    and (PerformanceTest3='OK' or PerformanceTest3='') and (PerformanceTest2='OK' or PerformanceTest2='')
    and (PerformanceTest4='OK' or PerformanceTest4='') and (PerformanceTest8='OK' or PerformanceTest8='') and DeformationResult='OK' and GaugeResult='OK'
    then 'OK' else 'NG' end from MES_Inspect i join(select c.billno, Appearance,Structure,[Assembly],Packing,PerformanceTest3,PerformanceTest2,PerformanceTest4,PerformanceTest8,
    case when (isnull(g.LongUpDeformationResult,'OK')='OK' or g.LongUpDeformationResult='') and (isnull(g.LongMiddleDeformationResult,'OK')='OK' or g.LongMiddleDeformationResult='') and (isnull(g.LongDownDeformationResult,'OK')='OK' or g.LongDownDeformationResult='') and
    (isnull(g.WidthUpDeformationResult,'OK')='OK' or g.WidthUpDeformationResult='') and (isnull(g.WidthMiddleDeformationResult,'OK')='OK' or g.WidthMiddleDeformationResult='') and (isnull(g.WidthDownDeformationResult,'OK')='OK' or g.WidthDownDeformationResult='') then 'OK' else 'NG' end DeformationResult
    ,case when (isnull(g.LongUpGaugeResult,'OK')='OK' or g.LongUpGaugeResult='') and (isnull(g.LongMiddleGaugeResult,'OK')='OK' or g.LongMiddleGaugeResult='') and (isnull(g.LongDownGaugeResult,'OK')='OK' or g.LongDownGaugeResult='')
    and (isnull(g.WidthUpGaugeResult,'OK')='OK' or g.WidthUpGaugeResult='') and (isnull(g.WidthMiddleGaugeResult,'OK')='OK' or g.WidthMiddleGaugeResult='') and (isnull(g.WidthDownGaugeResult,'OK')='OK' or g.WidthDownGaugeResult='') and isnull(g.WeightResult,'OK')='OK' then 'OK' else 'NG' end GaugeResult from MES_Inspect c
    left join
    (select billno,
    max(CASE ItemCode WHEN '1' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Appearance',
    max(CASE ItemCode WHEN '2' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Structure',
    max(CASE ItemCode WHEN '3' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Assembly',
    max(CASE ItemCode WHEN '4' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Packing',
    max(CASE ItemCode WHEN '6' THEN case when ItemValue='不合格' then 'NG' else 'OK' end END) AS 'PerformanceTest3',
    max(CASE ItemCode WHEN '5' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'PerformanceTest2',
    max(CASE ItemCode WHEN '7' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'PerformanceTest4',
    max(CASE ItemCode WHEN '8' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'PerformanceTest8'
    from MES_InspectSingle group by billno) s on c.BillNO=s.BillNO left join
    (select billno,
    max(CASE when ItemType=3 and ItemCode='上长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongUpGaugeResult',
    max(CASE when ItemType=3 and ItemCode='中长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongMiddleGaugeResult',
    max(CASE when ItemType=3 and ItemCode='下长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongDownGaugeResult',
    max(CASE when ItemType=3 and ItemCode='左宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthUpGaugeResult',
    max(CASE when ItemType=3 and ItemCode='中宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthMiddleGaugeResult',
    max(CASE when ItemType=3 and ItemCode='右宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthDownGaugeResult',
    max(CASE when ItemType=5 and ItemCode='上长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongUpDeformationResult',
    max(CASE when ItemType=5 and ItemCode='中长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongMiddleDeformationResult',
    max(CASE when ItemType=5 and ItemCode='下长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongDownDeformationResult',
    max(CASE when ItemType=5 and ItemCode='左宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthUpDeformationResult',
    max(CASE when ItemType=5 and ItemCode='中宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthMiddleDeformationResult',
    max(CASE when ItemType=5 and ItemCode='右宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthDownDeformationResult',
    max(CASE when ItemType=1 and ItemCode='重量' and Position='重量' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WeightResult'
    from MES_InspectGauge group by billno) g on g.BillNO=s.BillNO where checktype=2) a on i.billno=a.billno where i.billno=@BillNo
    end
    else if (@checktype=3)
    begin
    update i set checkresult=case when (Appearance='OK' or Appearance='') and (Structure='OK' or Structure='') and ([Assembly]='OK' or [Assembly]='') and (Packing='OK' or Packing='')
    and (DeviceIsNormal='OK' or DeviceIsNormal='') and (ParamIsNormal='OK' or ParamIsNormal='')
    and (ToolingIsNormal='OK' or ToolingIsNormal='') and (OperationIsNormal='OK' or OperationIsNormal='')
    and (PerformanceTest3='OK' or PerformanceTest3='') and DeformationResult='OK' and GaugeResult='OK'
    then 'OK' else 'NG' end from MES_Inspect i join (select c.billno, Appearance,Structure,[Assembly],Packing,DeviceIsNormal,ParamIsNormal,ToolingIsNormal,OperationIsNormal,PerformanceTest3,
    case when (isnull(g.LongUpDeformationResult,'OK')='OK' or g.LongUpDeformationResult='') and (isnull(g.LongMiddleDeformationResult,'OK')='OK' or g.LongMiddleDeformationResult='') and (isnull(g.LongDownDeformationResult,'OK')='OK' or g.LongDownDeformationResult='') and
    (isnull(g.WidthUpDeformationResult,'OK')='OK' or g.WidthUpDeformationResult='') and (isnull(g.WidthMiddleDeformationResult,'OK')='OK' or g.WidthMiddleDeformationResult='') and (isnull(g.WidthDownDeformationResult,'OK')='OK' or g.WidthDownDeformationResult='') then 'OK' else 'NG' end DeformationResult
    ,case when (isnull(g.LongUpGaugeResult,'OK')='OK' or g.LongUpGaugeResult='') and (isnull(g.LongMiddleGaugeResult,'OK')='OK' or g.LongMiddleGaugeResult='') and (isnull(g.LongDownGaugeResult,'OK')='OK' or g.LongDownGaugeResult='')
    and (isnull(g.WidthUpGaugeResult,'OK')='OK' or g.WidthUpGaugeResult='') and (isnull(g.WidthMiddleGaugeResult,'OK')='OK' or g.WidthMiddleGaugeResult='') and (isnull(g.WidthDownGaugeResult,'OK')='OK' or g.WidthDownGaugeResult='') and isnull(g.WeightResult,'OK')='OK' then 'OK' else 'NG' end GaugeResult from MES_Inspect c
    left join
    (select billno,
    max(CASE ItemCode WHEN '1' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Appearance',
    max(CASE ItemCode WHEN '2' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Structure',
    max(CASE ItemCode WHEN '3' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Assembly',
    max(CASE ItemCode WHEN '4' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Packing',
    max(CASE ItemCode WHEN '9' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'DeviceIsNormal',
    max(CASE ItemCode WHEN '11' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'ParamIsNormal',
    max(CASE ItemCode WHEN '10' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'ToolingIsNormal',
    max(CASE ItemCode WHEN '12' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'OperationIsNormal',
    max(CASE ItemCode WHEN '13' THEN case when ItemValue='不合格' then 'NG' else 'OK' end END) AS 'PerformanceTest3'
    from MES_InspectSingle group by billno) s on c.BillNO=s.BillNO left join
    (select billno,
    max(CASE when ItemType=3 and ItemCode='上长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongUpGaugeResult',
    max(CASE when ItemType=3 and ItemCode='中长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongMiddleGaugeResult',
    max(CASE when ItemType=3 and ItemCode='下长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongDownGaugeResult',
    max(CASE when ItemType=3 and ItemCode='左宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthUpGaugeResult',
    max(CASE when ItemType=3 and ItemCode='中宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthMiddleGaugeResult',
    max(CASE when ItemType=3 and ItemCode='右宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthDownGaugeResult',
    max(CASE when ItemType=5 and ItemCode='上长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongUpDeformationResult',
    max(CASE when ItemType=5 and ItemCode='中长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongMiddleDeformationResult',
    max(CASE when ItemType=5 and ItemCode='下长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongDownDeformationResult',
    max(CASE when ItemType=5 and ItemCode='左宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthUpDeformationResult',
    max(CASE when ItemType=5 and ItemCode='中宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthMiddleDeformationResult',
    max(CASE when ItemType=5 and ItemCode='右宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthDownDeformationResult',
    max(CASE when ItemType=1 and ItemCode='重量' and Position='重量' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WeightResult'
    from MES_InspectGauge group by billno) g on g.BillNO=s.BillNO where checktype=3) a on i.billno=a.billno where i.billno=@BillNo
    end
    else if (@checktype=4)
    begin
    update i set checkresult=case when (Appearance='OK' or Appearance='') and (Structure='OK' or Structure='') and ([Assembly]='OK' or [Assembly]='') and (Packing='OK' or Packing='')
    and (PerformanceTest3='OK' or PerformanceTest3='') and (PerformanceTest2='OK' or PerformanceTest2='')
    and (PerformanceTest4='OK' or PerformanceTest4='') and (PerformanceTest8='OK' or PerformanceTest8='') and DeformationResult='OK' and GaugeResult='OK'
    then 'OK' else 'NG' end from MES_Inspect i join (select c.billno, Appearance,Structure,[Assembly],Packing,PerformanceTest3,PerformanceTest2,PerformanceTest4,PerformanceTest8,
    case when (isnull(g.LongUpDeformationResult,'OK')='OK' or g.LongUpDeformationResult='') and (isnull(g.LongMiddleDeformationResult,'OK')='OK' or g.LongMiddleDeformationResult='') and (isnull(g.LongDownDeformationResult,'OK')='OK' or g.LongDownDeformationResult='') and
    (isnull(g.WidthUpDeformationResult,'OK')='OK' or g.WidthUpDeformationResult='') and (isnull(g.WidthMiddleDeformationResult,'OK')='OK' or g.WidthMiddleDeformationResult='') and (isnull(g.WidthDownDeformationResult,'OK')='OK' or g.WidthDownDeformationResult='') then 'OK' else 'NG' end DeformationResult
    ,case when (isnull(g.LongUpGaugeResult,'OK')='OK' or g.LongUpGaugeResult='') and (isnull(g.LongMiddleGaugeResult,'OK')='OK' or g.LongMiddleGaugeResult='') and (isnull(g.LongDownGaugeResult,'OK')='OK' or g.LongDownGaugeResult='')
    and (isnull(g.WidthUpGaugeResult,'OK')='OK' or g.WidthUpGaugeResult='') and (isnull(g.WidthMiddleGaugeResult,'OK')='OK' or g.WidthMiddleGaugeResult='') and (isnull(g.WidthDownGaugeResult,'OK')='OK' or g.WidthDownGaugeResult='') and isnull(g.WeightResult,'OK')='OK' then 'OK' else 'NG' end GaugeResult from MES_Inspect c
    left join
    (select billno,
    max(CASE ItemCode WHEN '1' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Appearance',
    max(CASE ItemCode WHEN '2' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Structure',
    max(CASE ItemCode WHEN '3' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Assembly',
    max(CASE ItemCode WHEN '4' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Packing',
    max(CASE ItemCode WHEN '6' THEN case when ItemValue='不合格' then 'NG' else 'OK' end END) AS 'PerformanceTest3',
    max(CASE ItemCode WHEN '5' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'PerformanceTest2',
    max(CASE ItemCode WHEN '7' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'PerformanceTest4',
    max(CASE ItemCode WHEN '8' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'PerformanceTest8'
    from MES_InspectSingle group by billno ) s on c.BillNO=s.BillNO left join
    (select billno,
    max(CASE when ItemType=3 and ItemCode='上长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongUpGaugeResult',
    max(CASE when ItemType=3 and ItemCode='中长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongMiddleGaugeResult',
    max(CASE when ItemType=3 and ItemCode='下长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongDownGaugeResult',
    max(CASE when ItemType=3 and ItemCode='左宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthUpGaugeResult',
    max(CASE when ItemType=3 and ItemCode='中宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthMiddleGaugeResult',
    max(CASE when ItemType=3 and ItemCode='右宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthDownGaugeResult',
    max(CASE when ItemType=5 and ItemCode='上长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongUpDeformationResult',
    max(CASE when ItemType=5 and ItemCode='中长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongMiddleDeformationResult',
    max(CASE when ItemType=5 and ItemCode='下长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongDownDeformationResult',
    max(CASE when ItemType=5 and ItemCode='左宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthUpDeformationResult',
    max(CASE when ItemType=5 and ItemCode='中宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthMiddleDeformationResult',
    max(CASE when ItemType=5 and ItemCode='右宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthDownDeformationResult',
    max(CASE when ItemType=1 and ItemCode='重量' and Position='重量' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WeightResult'
    from MES_InspectGauge group by billno) g on g.BillNO=s.BillNO where checktype=4) a on i.billno=a.billno where i.billno=@BillNo
    end
    else if (@checktype=5)
    begin
    update i set checkresult=case when (Appearance='OK' or Appearance='') and (Structure='OK' or Structure='') and ([Assembly]='OK' or [Assembly]='') and (Packing='OK' or Packing='')
    and DeformationResult='OK' and GaugeResult='OK' and (OtherProperties='OK' or OtherProperties='') and (RoHSConfirm='OK' or RoHSConfirm='') and (TearFilm='OK' or TearFilm='')
    and (Adhesion='OK' or Adhesion='') and i.InkHardness<>'不合格'
    then 'OK' else 'NG' end from MES_Inspect i join (select c.billno, Appearance,Structure,[Assembly],Packing,
    isnull(OtherProperties,'OK') OtherProperties,isnull(RoHSConfirm,'OK') RoHSConfirm,isnull(TearFilm,'OK') TearFilm,isnull(Adhesion,'OK') Adhesion,
    case when (isnull(g.LongUpDeformationResult,'OK')='OK' or g.LongUpDeformationResult='') and (isnull(g.LongMiddleDeformationResult,'OK')='OK' or g.LongMiddleDeformationResult='') and (isnull(g.LongDownDeformationResult,'OK')='OK' or g.LongDownDeformationResult='') and
    (isnull(g.WidthUpDeformationResult,'OK')='OK' or g.WidthUpDeformationResult='') and (isnull(g.WidthMiddleDeformationResult,'OK')='OK' or g.WidthMiddleDeformationResult='') and (isnull(g.WidthDownDeformationResult,'OK')='OK' or g.WidthDownDeformationResult='') then 'OK' else 'NG' end DeformationResult
    ,case when (isnull(g.LongUpGaugeResult,'OK')='OK' or g.LongUpGaugeResult='') and (isnull(g.LongMiddleGaugeResult,'OK')='OK' or g.LongMiddleGaugeResult='') and (isnull(g.LongDownGaugeResult,'OK')='OK' or g.LongDownGaugeResult='')
    and (isnull(g.WidthUpGaugeResult,'OK')='OK' or g.WidthUpGaugeResult='') and (isnull(g.WidthMiddleGaugeResult,'OK')='OK' or g.WidthMiddleGaugeResult='') and (isnull(g.WidthDownGaugeResult,'OK')='OK' or g.WidthDownGaugeResult='') and isnull(g.WeightResult,'OK')='OK' then 'OK' else 'NG' end GaugeResult from MES_Inspect c
    left join
    (select billno,
    max(CASE ItemCode WHEN 'Appearance' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Appearance',
    max(CASE ItemCode WHEN 'Structure' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Structure',
    max(CASE ItemCode WHEN 'Assembly' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Assembly',
    max(CASE ItemCode WHEN 'Packing' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Packing',
    max(CASE ItemCode WHEN 'OtherProperties' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'OtherProperties',
    max(CASE ItemCode WHEN 'RoHSConfirm' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'RoHSConfirm',
    max(CASE ItemCode WHEN 'TearFilm' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'TearFilm',
    max(CASE ItemCode WHEN 'Adhesion' THEN case when ItemValue='' then 'OK' else ItemValue end END) AS 'Adhesion'
    from MES_InspectSingle group by billno) s on c.BillNO=s.BillNO left join
    (select billno,
    max(CASE when ItemType=3 and ItemCode='上长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongUpGaugeResult',
    max(CASE when ItemType=3 and ItemCode='中长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongMiddleGaugeResult',
    max(CASE when ItemType=3 and ItemCode='下长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongDownGaugeResult',
    max(CASE when ItemType=3 and ItemCode='左宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthUpGaugeResult',
    max(CASE when ItemType=3 and ItemCode='中宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthMiddleGaugeResult',
    max(CASE when ItemType=3 and ItemCode='右宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthDownGaugeResult',
    max(CASE when ItemType=5 and ItemCode='上长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongUpDeformationResult',
    max(CASE when ItemType=5 and ItemCode='中长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongMiddleDeformationResult',
    max(CASE when ItemType=5 and ItemCode='下长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongDownDeformationResult',
    max(CASE when ItemType=5 and ItemCode='左宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthUpDeformationResult',
    max(CASE when ItemType=5 and ItemCode='中宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthMiddleDeformationResult',
    max(CASE when ItemType=5 and ItemCode='右宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthDownDeformationResult',
    max(CASE when ItemType=1 and ItemCode='重量' and Position='重量' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WeightResult'
    from MES_InspectGauge group by billno) g on g.BillNO=s.BillNO where checktype=5) a on i.billno=a.billno where i.billno=@BillNo
    end
    else if (@checktype=6)
    begin
    update i set checkresult=case when (PerformanceTest1='OK' or PerformanceTest1='') and (PerformanceTest2='OK' or PerformanceTest2='') and (PerformanceTest3='OK' or PerformanceTest3='') and (PerformanceTest4='OK' or PerformanceTest4='')
    and (PerformanceTest5='OK' or PerformanceTest5='') and (PerformanceTest6='OK' or PerformanceTest6='') and (PerformanceTest7='OK' or PerformanceTest7='') and (PerformanceTest8='OK' or PerformanceTest8='') and (PerformanceTest9='OK' or PerformanceTest9='')
    and (PerformanceTest10='OK' or PerformanceTest10='') and (PerformanceTest11='OK' or PerformanceTest11='') and (PackagingProject1='OK' or PackagingProject1='') and (PackagingProject2='OK' or PackagingProject2='') and (PackagingProject3='OK' or PackagingProject3='') and
    (PackagingProject4='OK' or PackagingProject4='') and (VisualInspection1='OK' or VisualInspection1='') and (VisualInspection2='OK' or VisualInspection2='') and (VisualInspection3='OK' or VisualInspection3='') and (VisualInspection4='OK' or VisualInspection4='')
    and (VisualInspection5='OK' or VisualInspection5='') and (VisualInspection6='OK' or VisualInspection6='') and DeformationResult='OK' and GaugeResult='OK' and i.InkHardness<>'不合格'
    then 'OK' else 'NG' end from MES_Inspect i join (select c.billno, PerformanceTest1,PerformanceTest2,PerformanceTest3,PerformanceTest4,PerformanceTest5,PerformanceTest6,PerformanceTest7,PerformanceTest8,
    PerformanceTest9,PerformanceTest10,PerformanceTest11,PackagingProject1,PackagingProject2,PackagingProject3,PackagingProject4,VisualInspection1,VisualInspection2,VisualInspection3,VisualInspection4,
    VisualInspection5,VisualInspection6,
    case when (isnull(g.LongUpDeformationResult,'OK')='OK' or g.LongUpDeformationResult='') and (isnull(g.LongMiddleDeformationResult,'OK')='OK' or g.LongMiddleDeformationResult='') and (isnull(g.LongDownDeformationResult,'OK')='OK' or g.LongDownDeformationResult='') and
    (isnull(g.WidthUpDeformationResult,'OK')='OK' or g.WidthUpDeformationResult='') and (isnull(g.WidthMiddleDeformationResult,'OK')='OK' or g.WidthMiddleDeformationResult='') and (isnull(g.WidthDownDeformationResult,'OK')='OK' or g.WidthDownDeformationResult='') then 'OK' else 'NG' end DeformationResult
    ,case when (isnull(g.LongUpGaugeResult,'OK')='OK' or g.LongUpGaugeResult='') and (isnull(g.LongMiddleGaugeResult,'OK')='OK' or g.LongMiddleGaugeResult='') and (isnull(g.LongDownGaugeResult,'OK')='OK' or g.LongDownGaugeResult='')
    and (isnull(g.WidthUpGaugeResult,'OK')='OK' or g.WidthUpGaugeResult='') and (isnull(g.WidthMiddleGaugeResult,'OK')='OK' or g.WidthMiddleGaugeResult='') and (isnull(g.WidthDownGaugeResult,'OK')='OK' or g.WidthDownGaugeResult='') and isnull(g.WeightResult,'OK')='OK' then 'OK' else 'NG' end GaugeResult from MES_Inspect c
    left join
    (select billno,
    max(CASE ItemCode WHEN 'PerformanceTest1' THEN ItemValue END) AS 'PerformanceTest1',
    max(CASE ItemCode WHEN 'PerformanceTest2' THEN ItemValue END) AS 'PerformanceTest2',
    max(CASE ItemCode WHEN 'PerformanceTest3' THEN ItemValue END) AS 'PerformanceTest3',
    max(CASE ItemCode WHEN 'PerformanceTest4' THEN ItemValue END) AS 'PerformanceTest4',
    max(CASE ItemCode WHEN 'PerformanceTest5' THEN ItemValue END) AS 'PerformanceTest5',
    max(CASE ItemCode WHEN 'PerformanceTest6' THEN ItemValue END) AS 'PerformanceTest6',
    max(CASE ItemCode WHEN 'PerformanceTest7' THEN ItemValue END) AS 'PerformanceTest7',
    max(CASE ItemCode WHEN 'PerformanceTest8' THEN ItemValue END) AS 'PerformanceTest8',
    max(CASE ItemCode WHEN 'PerformanceTest9' THEN ItemValue END) AS 'PerformanceTest9',
    max(CASE ItemCode WHEN 'PerformanceTest10' THEN ItemValue END) AS 'PerformanceTest10',
    max(CASE ItemCode WHEN 'PerformanceTest11' THEN ItemValue END) AS 'PerformanceTest11',
    max(CASE ItemCode WHEN 'PackagingProject1' THEN ItemValue END) AS 'PackagingProject1',
    max(CASE ItemCode WHEN 'PackagingProject2' THEN ItemValue END) AS 'PackagingProject2',
    max(CASE ItemCode WHEN 'PackagingProject3' THEN ItemValue END) AS 'PackagingProject3',
    max(CASE ItemCode WHEN 'PackagingProject4' THEN ItemValue END) AS 'PackagingProject4',
    max(CASE ItemCode WHEN 'VisualInspection1' THEN ItemValue END) AS 'VisualInspection1',
    max(CASE ItemCode WHEN 'VisualInspection2' THEN ItemValue END) AS 'VisualInspection2',
    max(CASE ItemCode WHEN 'VisualInspection3' THEN ItemValue END) AS 'VisualInspection3',
    max(CASE ItemCode WHEN 'VisualInspection4' THEN ItemValue END) AS 'VisualInspection4',
    max(CASE ItemCode WHEN 'VisualInspection5' THEN ItemValue END) AS 'VisualInspection5',
    max(CASE ItemCode WHEN 'VisualInspection6' THEN ItemValue END) AS 'VisualInspection6'
    from MES_InspectSingle group by billno) s on c.BillNO=s.BillNO left join
    (select billno,
    max(CASE when ItemType=3 and ItemCode='上长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongUpGaugeResult',
    max(CASE when ItemType=3 and ItemCode='中长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongMiddleGaugeResult',
    max(CASE when ItemType=3 and ItemCode='下长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongDownGaugeResult',
    max(CASE when ItemType=3 and ItemCode='左宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthUpGaugeResult',
    max(CASE when ItemType=3 and ItemCode='中宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthMiddleGaugeResult',
    max(CASE when ItemType=3 and ItemCode='右宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthDownGaugeResult',
    max(CASE when ItemType=5 and ItemCode='上长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongUpDeformationResult',
    max(CASE when ItemType=5 and ItemCode='中长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongMiddleDeformationResult',
    max(CASE when ItemType=5 and ItemCode='下长' and Position='长' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'LongDownDeformationResult',
    max(CASE when ItemType=5 and ItemCode='左宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthUpDeformationResult',
    max(CASE when ItemType=5 and ItemCode='中宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthMiddleDeformationResult',
    max(CASE when ItemType=5 and ItemCode='右宽' and Position='宽' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WidthDownDeformationResult',
    max(CASE when ItemType=1 and ItemCode='重量' and Position='重量' THEN case when CheckResult='' then 'OK' else CheckResult end END) AS 'WeightResult'
    from MES_InspectGauge group by billno) g on g.BillNO=s.BillNO where checktype=6) a on i.billno=a.billno where i.billno=@BillNo
    end
    END

  • 相关阅读:
    《SPFA算法的优化及应用》——姜碧野(学习笔记)
    hdu 4691 Front compression
    hdu 4690 EBCDIC
    UVA 11478 Halum(用bellman-ford解差分约束)
    UVA 11090 Going in Cycle!!(二分答案+判负环)
    UVA 10537 The Toll! Revisited uva1027 Toll(最短路+数学坑)
    hdu 4674 Trip Advisor(缩点+倍增lca)
    canny算子原理
    二值图像连通区域标记
    C++全局变量的声明和定义
  • 原文地址:https://www.cnblogs.com/chengjun/p/4845467.html
Copyright © 2011-2022 走看看