2012-05-26 306 views
-8

我不知道SQL或嵌套語句。請根據我的標準和下面的SQL爲我提供完整的SQL以複製並粘貼到我的Access查詢中。 非常感謝你提前,納撒尼爾嵌套if語句

標準

  1. if [POsoI].[PO_number]is like "*H", THEN [o].[SERVICE ID] must be equal to "HEAT TREAT"

  2. IF [POsoI].[PO_number] is like "*C", THEN [o].[SERVICE ID] must be equal to "COATING" or equal to "ZINC PLATING"

  3. IF [POsoI].[PO_number] is like "*G", THEN [o].[SERVICE ID] must be equal to "GRINDING"

  4. IF [POsoI].[.[PO_number] isnt like "*H" or like "*C" or like "*G", then [o].[SERVICE ID] must not be null and can not be equal to "HEAT TREAT" and can not be equal to "COATING" and can not be equal to"ZINC PLATING" and can not be equal to "GRINDING"

    SELECT DISTINCT o.SERVICE_ID FROM tbl_PO_service_order_input AS POsoI INNER JOIN SYSADM_OPERATION AS o ON (o.WORKORDER_LOT_ID = POsoI.WO_lot_ID) AND (POsoI.wo_Base_ID = o.WORKORDER_BASE_ID);

+3

[自學在21天SQL](http://www8.silversand.net/techdoc/teachsql/index.htm) –

+0

@邁克爾Petrotta:偉大的評論: - ) – Philipp

+0

謝謝你的建議,但不幸的是,我沒有21天的時間學習。 –

回答

0
SELECT DISTINCT IIf(RIGHT(TBL_PO_SERVICE_ORDER_INPUT.PO_NUMBER,1)='H' And SYSADM_OPERATION.SERVICE_ID='HEAT TREAT',SYSADM_OPERATION.SERVICE_ID,IIf(RIGHT(TBL_PO_SERVICE_ORDER_INPUT.PO_NUMBER,1)='C' And SYSADM_OPERATION.SERVICE_ID='CLOTHING' Or SYSADM_OPERATION.SERVICE_ID='ZINC PLATING',SYSADM_OPERATION.SERVICE_ID,IIf(RIGHT(TBL_PO_SERVICE_ORDER_INPUT.PO_NUMBER,1)='G' And SYSADM_OPERATION.SERVICE_ID='GRINDING',SYSADM_OPERATION.SERVICE_ID,IIf(RIGHT(TBL_PO_SERVICE_ORDER_INPUT.PO_NUMBER,1)<>'G' Or RIGHT(TBL_PO_SERVICE_ORDER_INPUT.PO_NUMBER,1)<>'H' Or RIGHT(TBL_PO_SERVICE_ORDER_INPUT.PO_NUMBER,1)<>'C' And SYSADM_OPERATION.SERVICE_ID Is Not Null,SYSADM_OPERATION.SERVICE_ID, 
IIf(SYSADM_OPERATION.SERVICE_ID<>'HEAT TREAT' And SYSADM_OPERATION.SERVICE_ID<>'COATING' And SYSADM_OPERATION.SERVICE_ID<>'ZINC PLATING' And SYSADM_OPERATION.SERVICE_ID<>'GRINDING',SYSADM_OPERATION.SERVICE_ID))))) 
FROM SYSADM_OPERATION INNER JOIN TBL_PO_SERVICE_ORDER_INPUT ON ([TBL_PO_SERVICE_ORDER_INPUT].WO_LOT_ID=[SYSADM_OPERATION].WORKORDER_LOT_ID) AND ([TBL_PO_SERVICE_ORDER_INPUT].WO_BASE_ID=[SYSADM_OPERATION].WORKORDER_BASE_ID); 
+0

非常感謝! –