You are on page 1of 2

SELECT d1.ORGANIZATION_ID, d1.PLAN_ID,d1.

OCCURRENCE,
qr.item_id,
qr.date_opened,
qr.UOM,
qr.NONCONFORMANCE_SOURCE,
qr.Quantity as Original_Quantity,
qr.NONCONFORM_PRIORITY as Priority,
MAX(D1."NC_Number") AS "NC_Number",
MAX(D1."Item_Description") AS "Item_Description",
MAX(D1."Lot_number") AS "Lot_number",
MAX(D1."NC_Qty") AS "NC_Qty",
MAX(D1."Comment") AS "Comment",
MAX(D1."Nonconformance_Status_MNS") AS "Nonconformance_Status_MNS",
MAX(D1."Reason") AS "Reason",
MAX(D1."Corrective_action") AS "Corrective_action",
MAX(D1."Department") AS "Department",
MAX(D1."Nonconformance_Type_MNS") AS "Nonconformance_Type_MNS",
MAX(D1."Subinventory") AS "Subinventory",
MAX(D1."Entered_by_User") AS "Entered_by_User",
MAX(D1."Total_NC_cost") AS "Total_NC_cost",
MAX(D1."QC_name") AS "QC_name",
MAX(D1."Ghi_chu") AS "Ghi_chu",
MAX(D1."NC_Origin") AS "NC_Origin",
MAX(D1."Email_Address") AS "Email_Address",
MAX(D1."NC_Root_cause") AS "NC_Root_cause",
MAX(D1."CAR_Required") AS "CAR_Required",
MAX(D1."Car_number") AS "Car_number",
MAX(D1."Dispose_quantity") AS "Dispose_quantity",
MAX(D1."Dispose_cost") AS "Dispose_cost",
MAX(D1."Total_dispose_cost") AS "Total_dispose_cost",
MAX(D1."Transportation_cost") AS "Transportation_cost",
MAX(D1."NC_cost_of_retirement") AS "NC_cost_of_retirement",
MAX(D1."Material_cost") AS "Material_cost",
MAX(D1."Resource_cost") AS "Resource_cost",
MAX(D1."Rework_cost") AS "Rework_cost",
MAX(D1."Other_cost") AS "Other_cost"
FROM
( SELECT *
FROM
(
SELECT C1.COLLECTION_ID,
C1.OCCURRENCE,
C1.TXN_HEADER_ID,
C1.ORGANIZATION_ID,
C1.PLAN_ID,
C1.A_CHAR,
C1.A_VALUE,
C2.PROMPT
FROM
( SELECT *
FROM QA.QA_RESULTS
UNPIVOT INCLUDE NULLS
( A_VALUE
FOR A_CHAR
IN ("SEQUENCE1","CHARACTER1", "CHARACTER2", "CHARACTER3",
"CHARACTER4", "CHARACTER5", "CHARACTER6", "CHARACTER7", "CHARACTER8",
"CHARACTER9", "CHARACTER10", "CHARACTER11", "CHARACTER12", "CHARACTER13",
"CHARACTER14", "CHARACTER15", "CHARACTER16", "CHARACTER17", "CHARACTER18",
"CHARACTER19", "CHARACTER20", "CHARACTER21", "CHARACTER22", "CHARACTER23",
"CHARACTER24", "CHARACTER25", "CHARACTER26", "CHARACTER27", "CHARACTER28",
"CHARACTER29", "CHARACTER30", "CHARACTER31", "CHARACTER32", "CHARACTER33",
"CHARACTER34", "CHARACTER35", "CHARACTER36", "CHARACTER37", "CHARACTER38",
"CHARACTER39", "CHARACTER40", "CHARACTER41", "CHARACTER42", "CHARACTER43",
"CHARACTER44", "CHARACTER45", "CHARACTER46", "CHARACTER47", "CHARACTER48",
"CHARACTER49", "CHARACTER50", "CHARACTER51", "CHARACTER52", "CHARACTER53",
"CHARACTER54", "CHARACTER55", "CHARACTER56", "CHARACTER57", "CHARACTER58",
"CHARACTER59", "CHARACTER60", "CHARACTER61", "CHARACTER62", "CHARACTER63",
"CHARACTER64", "CHARACTER65", "CHARACTER66", "CHARACTER67", "CHARACTER68",
"CHARACTER69", "CHARACTER70", "CHARACTER71", "CHARACTER72", "CHARACTER73",
"CHARACTER74", "CHARACTER75", "CHARACTER76", "CHARACTER77", "CHARACTER78",
"CHARACTER79", "CHARACTER80", "CHARACTER81", "CHARACTER82", "CHARACTER83",
"CHARACTER84", "CHARACTER85", "CHARACTER86", "CHARACTER87", "CHARACTER88",
"CHARACTER89", "CHARACTER90", "CHARACTER91", "CHARACTER92", "CHARACTER93",
"CHARACTER94", "CHARACTER95", "CHARACTER96", "CHARACTER97", "CHARACTER98",
"CHARACTER99", "CHARACTER100" ) )
) C1,
qa.QA_PLAN_CHARS C2
WHERE C1.PLAN_ID = C2.PLAN_ID
AND C1.A_CHAR = C2.RESULT_COLUMN_NAME
--AND C1.PLAN_ID = 22168
--AND C1.COLLECTION_ID = 4210842
--AND C1.OCCURRENCE = 892402
) D1
PIVOT
(MAX(A_VALUE) FOR PROMPT IN ('NC Number'AS "NC_Number",'Item Description' AS
"Item_Description", 'Lot number' AS "Lot_number", 'Comment' AS "Comment",
'Nonconformance Status MNS' AS "Nonconformance_Status_MNS", 'NC Qty' AS
"NC_Qty", 'Reason' AS "Reason", 'Corrective action' AS "Corrective_action",
'Department' AS "Department", 'Nonconformance Type MNS' AS
"Nonconformance_Type_MNS", 'Subinventory' AS "Subinventory", 'Entered by User'
AS "Entered_by_User", 'Total NC cost' AS "Total_NC_cost", 'QC name' AS
"QC_name", 'Ghi ch�' AS "Ghi_chu", 'NC Origin' AS "NC_Origin", 'Email Address'
AS "Email_Address", 'NC Root cause' AS "NC_Root_cause", 'CAR Required ?' AS
"CAR_Required", 'Car number' AS "Car_number", 'Dispose quantity' AS
"Dispose_quantity", 'Dispose cost' AS "Dispose_cost", 'Total dispose cost' AS
"Total_dispose_cost", 'Transportation cost' AS "Transportation_cost", 'NC cost
of retirement' AS "NC_cost_of_retirement", 'Material cost' AS "Material_cost",
'Resource cost' AS "Resource_cost", 'Rework cost' AS "Rework_cost", 'Other cost'
AS "Other_cost")
)
) D1,
qa_results qr,
apps.org_organization_definitions ood
WHERE 1=1
and d1.organization_id = ood.organization_id
AND ood.chart_of_accounts_id = '50469'
and d1.occurrence = qr.occurrence
GROUP BY d1.ORGANIZATION_ID,
d1.PLAN_ID,d1.OCCURRENCE,qr.item_id,qr.date_opened,qr.UOM,qr.NONCONFORMANCE_SOURCE,
qr.Quantity
,qr.NONCONFORM_PRIORITY

You might also like