View Full Version : How to rewrite the multiple IIF statements


boblarson
04-30-2008, 01:30 PM
Okay, slowly I'm getting acclimated to this. Thanks to Kiwiman I managed to get my Update queries converted.

I have run into another issue that I've not yet faced. I need to convert the IIF statements in this (I know that I can use CASE and I've done that with a simple one, but with the OR's in this Having Clause I'm not sure exactly how to write it.


HAVING (((Sum(IIf([FINAL_DELIVERY]='X',0,[PO_QTY_SIZE]-[RECEIVED_QTY])))>0)
AND (([base - 7117 PO].PLANT)='1051')) OR
(((Sum(IIf([FINAL_DELIVERY]='X',0,[PO_QTY_SIZE]-[RECEIVED_QTY])))>0) AND
(([base - 7117 PO].PLANT)='1060'));

georgedwilkinson
04-30-2008, 02:16 PM
Howz 'bout:

HAVING ((case when [FINAL_DELIVERY] <> 'X' then sum([PO_QTY_SIZE]-[RECEIVED_QTY]) else 0 end) > 0)
AND
[base - 7117 PO].PLANT) in ('1051', '1060');

I think. It's been since my Oracle days doing something like this.

Also, I may have over-simplified the "OR" portion.

boblarson
04-30-2008, 02:16 PM
Never mind - I figured it out:


HAVING (((Sum(Case [FINAL_DELIVERY]
When 'X' Then 0
Else [PO_QTY_SIZE]-[RECEIVED_QTY] End))>0)
AND (([base - 7117 PO].PLANT)='1051')) OR
(((Sum(Case [FINAL_DELIVERY] WHEN 'X' THEN 0
ELSE [PO_QTY_SIZE]-[RECEIVED_QTY] End))>0) AND
(([base - 7117 PO].PLANT)='1060'));