日期:2014-05-17 浏览次数:20470 次
DECLARE
@Index INT
,@LastIndex INT
,@PN VARCHAR(25)
SET @Index = (SELECT CHARINDEX(':',@PartNumber))
SET @LastIndex = (SELECT CHARINDEX('(',@PartNumber))
SET @PN = (CASE WHEN LEN(@PartNumber) > 25 THEN SUBSTRING(@PartNumber,@Index+2,((@LastIndex-4)-(@Index -1))) ELSE @PartNumber END)
CREATE TABLE #TblPass
(ProductionOrder VARCHAR(25)
,PartNumber VARCHAR(25)
,PartDesc VARCHAR(100)
,TestDesc VARCHAR(100)
,PassQty INT)
CREATE TABLE #TblFail
(ProductionOrder VARCHAR(25)
,PartNumber VARCHAR(25)
,PartDesc VARCHAR(100)
,TestDesc VARCHAR(100)
,FailQty INT)
CREATE TABLE #TblFinal
(ProductionOrder VARCHAR(25)
,PartNumber VARCHAR(25)
,PartDesc VARCHAR(100)
,TestDesc VARCHAR(100)
,PassQty INT
,FailQty INT
,Total INT
,Yield FLOAT
,TestStart DATETIME
,ProdOrderStart DATETIME)
CREATE TABLE #TblTestSteps
(ProductionOrder VARCHAR(25)
,TestDesc VARCHAR(100)
,StartDate DATETIME)
CREATE TABLE #TblPN
(JDSUPartNumber VARCHAR(50)
,PartNumber VARCHAR(50))
INSERT INTO #TblPN
SELECT
JDSUPartNumber
,BEIPartNumber
FROM
TblPartLookUp
WHERE
JDSUPartNumber = @PN
INSERT INTO #TblTestSteps
SELECT
ProductionOrder
,TestDescription
,MIN(TestDateTime)
FROM
TblTestData
WHERE
ProductionOrder IN (SELECT
ProductionOrder
FROM
TblProductionOrders
WHERE
JDSUPartNumber = @PN
AND
StartTime BETWEEN @Start AND @End)
GROUP BY
ProductionOrder,TestDescription
INSERT INTO #TblPass
SELECT
ProductionOrder
,PartNumber
,PartDescription
,TestDescription
,COUNT(DISTINCT SerialNumber) AS QTY
FROM
TblTestData
WHERE
SerialNumber IN (SELECT
SerialNumber
FROM
TblSerialNumbers
WHERE
StartDate BETWEEN @Start AND @End)
AND
PartNumber IN (SELECT
PartNumber
FROM #TblPN)
AND
CycleNumber = 1
AND
Result = 'P'
GROUP BY
ProductionOrder
,PartNumber
,PartDescription
,TestDescription
INSERT INTO #TblFail
SELECT
ProductionOrder
,PartNumber
,PartDescription
,TestDescription
,COUNT(DISTINCT SerialNumber) AS QTY
FROM
TblTestData
WHERE
SerialNumber IN (SELECT
SerialNumber
FROM