SANDING_DATE, SANDING_TIME, SANDING_DATEE, SANDING_TIMEE, SHIFT_ID, STATION_ID, STAFF_NAME, QC_NAME, SHIFT_SUP_NAME, REMARK, CREATE_BY,
CREATE_DATETIME, REVISE_BY, REVISE_DATETIME, UNIT_ID
FROM CUTTOSIZE_DTL_TEMP
WHERE (NOT EXISTS
(SELECT CTS_MST_ID, CTS_DTL_ID, CTS_DTL_ORDER, PRODUCT_ID, GRADE_ID, GLUE, CTS_LENGTH, CTS_WIDTH, CTS_THICK, QTY, CTS_DATETIMES,
CTS_DATETIMEE, SANDING_DATE, SANDING_TIME, SANDING_DATEE, SANDING_TIMEE, SHIFT_ID, STATION_ID, STAFF_NAME, QC_NAME,
SHIFT_SUP_NAME, REMARK, CREATE_BY, CREATE_DATETIME, REVISE_BY, REVISE_DATETIME, UNIT_ID
FROM CUTTOSIZE_DTL
WHERE (CTS_MST_ID = CUTTOSIZE_DTL_TEMP.CTS_MST_ID) AND (CTS_DTL_ID = CUTTOSIZE_DTL_TEMP.CTS_DTL_ID)))
SELECT ROW_NUMBER() OVER(ORDER BY INVENTORY_IN.ORDER_NO DESC) AS ORDER_NO,INVENTORY_IN.INVENT_IN_ID, INVENTORY_IN.INVENT_IN_DOCNO, CONVERT(VARCHAR, INVENTORY_IN.INVENT_IN_DOCDATE, 103)
AS INVENT_IN_DOCDATE, INVENTORY_IN.PACK_ID, INVENTORY_IN.PRODUCT_ID, INVENTORY_IN.GRADE_ID,
INVENTORY_IN.INVENT_QTY, INVENTORY_IN.UNIT_ID, INVENTORY_IN.INVENT_ID, INVENTORY_IN.INVENT_RECIEVER,
INVENTORY_IN.CREATE_DATETIME, INVENTORY_IN.CREATE_BY, INVENTORY_IN.REVISE_DATETIME, INVENTORY_IN.REVISE_BY,
INVENTORY_IN.REMARK, GRADE.GRADE_NAMET, EMPLOYEE_PROFILE.EMP_NAME_THAI + ' ' + EMPLOYEE_PROFILE.EMP_SURNAME_THAI AS FULLNAME,
INVENTORY_IN.INVENT_RECIEVE_DATE, INVENTORY_IN.BARCODE, INVENTORY_IN.LOTNO, PRODUCT_PROFILE.PRODUCT_CODE,
PRODUCT_PROFILE.PRODUCT_NAMET, PRODUCT_UNIT.UNIT_NAMET, INVENTORY.INVENT_DESCRIPTION, INVENT_BAL.QTY,
CASE INVENT_BAL.QTY - INVENTORY_IN.INVENT_QTY WHEN 0 THEN 'ACCEPT' END AS PERMISSION
FROM GRADE RIGHT OUTER JOIN
EMPLOYEE_PROFILE RIGHT OUTER JOIN
PRODUCT_PROFILE RIGHT OUTER JOIN
INVENTORY_IN LEFT OUTER JOIN
INVENT_BAL ON INVENTORY_IN.INVENT_IN_ID = INVENT_BAL.IN_ID ON
PRODUCT_PROFILE.PRODUCT_ID = INVENTORY_IN.PRODUCT_ID LEFT OUTER JOIN
INVENTORY ON INVENTORY_IN.INVENT_ID = INVENTORY.INVENT_ID ON EMPLOYEE_PROFILE.ID = INVENTORY_IN.INVENT_RECIEVER ON
GRADE.GRADE_ID = INVENTORY_IN.GRADE_ID LEFT OUTER JOIN
PRODUCT_UNIT ON PRODUCT_PROFILE.UNIT_ID = PRODUCT_UNIT.UNIT_ID
WHERE INVENTORY_IN.INVENT_IN_ID NOT IN (
SELECT INVENTORY_IN_TEMP.INVENT_IN_ID
FROM GRADE RIGHT OUTER JOIN
EMPLOYEE_PROFILE RIGHT OUTER JOIN
PRODUCT_PROFILE RIGHT OUTER JOIN
INVENTORY_IN_TEMP LEFT OUTER JOIN
INVENT_BAL ON INVENTORY_IN_TEMP.INVENT_IN_ID = INVENT_BAL.IN_ID ON
PRODUCT_PROFILE.PRODUCT_ID = INVENTORY_IN_TEMP.PRODUCT_ID LEFT OUTER JOIN
INVENTORY ON INVENTORY_IN_TEMP.INVENT_ID = INVENTORY.INVENT_ID ON EMPLOYEE_PROFILE.ID = INVENTORY_IN_TEMP.INVENT_RECIEVER ON
GRADE.GRADE_ID = INVENTORY_IN_TEMP.GRADE_ID LEFT OUTER JOIN
PRODUCT_UNIT ON PRODUCT_PROFILE.UNIT_ID = PRODUCT_UNIT.UNIT_ID )
ขออธิบายสั้นๆนะครับ ให้นำ Table ที่เป็นข้อมูลหลักไว้เป็น Table ตั้งต้นนะครับ จากนั้น คือ WHERE ด้วย ตารางที่ข้อมูลหายไป ไม่งั้นจะไม่เจอข้อมูลนะครับ
ไม่มีความคิดเห็น:
แสดงความคิดเห็น