NTF相关函数.sql 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. USE [MES]
  2. GO
  3. /****** Object: UserDefinedFunction [dbo].[GET_HOURRESULT] Script Date: 12/14/2021 10:28:25 ******/
  4. SET ANSI_NULLS ON
  5. GO
  6. SET QUOTED_IDENTIFIER ON
  7. GO
  8. ALTER FUNCTION [dbo].[GET_HOURRESULT](
  9. @Line varchar(30),
  10. @Station varchar(30),
  11. @ODF varchar(30),
  12. @TestDate DATE,
  13. @TestHour INT)
  14. RETURNS TABLE as
  15. RETURN select
  16. --抄写总数(包含重流和非重流的)
  17. Total = count(1),-- as 'Total',
  18. --实际数量:非重流的,即ReDo=0
  19. RealTotal = count(case when ReDo = '0' then 1 else null end),-- as 'RealTotal',
  20. --有且只有一次测试且成功 Test01=FinalTest=PASS & Test02=NULL
  21. OncePass = count(case when ResultType = 'OncePass' then 1 else null end),-- as 'OncePass',
  22. --有且只有一次测试且失败 Test01=FinalTest=FAIL & Test02=NULL
  23. OnceFail = count(case when ResultType = 'OnceFail' then 1 else null end),-- as 'OnceFail',
  24. --抄写2次或2次以上:Test01=FAIL & Test02=FinalTest=PASS
  25. NTF = count(case when ResultType = 'NTF' then 1 else null end),-- as 'NTF',
  26. --抄写2次或2次以上:Test01=Test02=FinalTest=FAIL
  27. TwiceFail = count(case when ResultType = 'TwiceFail' then 1 else null end),-- as 'TwiceFail',
  28. --2次或2次以上:Test01=PASS & Test02=FinalTest=FAIL
  29. --或者 抄写3次及以上:Test01=Test02=PASS & FinalTest=FAIL
  30. --或者 抄写3次及以上:Test01=FAIL & Test02=PASS & FinalTest=FAIL
  31. FinalFail = count(case when ResultType = 'FinalFail' then 1 else null end),-- as 'FinalFail',
  32. --2次或2次以上:Test01=Test02=FinalTest=PASS
  33. --或者 抄写3次及以上:Test01=FinalTest=PASS & Test02=FAIL
  34. FinalPass = count(case when ResultType = 'FinalPass' then 1 else null end),-- as 'FinalPass',
  35. --真实成功:Redo=0的SN.
  36. RealPass = count(case when FinalTest = 'PASS' and ReDo = '0' then 1 else null end),-- as 'RealPass',
  37. --真实失败:Redo=0的SN.
  38. RealFail = count(case when FinalTest = 'FAIL' and ReDo = '0' then 1 else null end),-- as 'RealFail',
  39. NTFSN = stuff((select ',' + SN from AMResult where Line=@Line and Station=@Station and ODF=@ODF and TestDate=@TestDate and TestHour=@TestHour and ResultType='NTF' for XML PATH('')),1,1,''),-- as 'NTFSN',
  40. FailDSN = stuff((select ',' + DSN from AMResult where Line=@Line and Station=@Station and ODF=@ODF and TestDate=@TestDate and TestHour=@TestHour and FinalTest='FAIL' for XML PATH('')),1,1,'')-- as 'FailDSN'
  41. from AMResult where Line=@Line and Station=@Station and ODF=@ODF and TestDate=@TestDate and TestHour=@TestHour
  42. --HourlyResultTR