I have a nested if statement in order to identify part_ID‘s that were sold below the proper unit price, for given price-break Qty (qb=qty break and up=unit price). The query works properly for most records, but around 30% of the records, the proper price field is null when it should be populated. I assume that there must be a bug in my query. I would be super grateful if somebody could debug. Ideally, you could give me the proper SQL for me to copy and paste.
SELECT tlsp.PART_ID,
IIf(IsNull([tlsp].[qb1])
And [tlsp].[last_sell_prc_cstmr]<[tlsp].[last_sell_prc_cstmr],
[tlsp].[last_sell_prc_cstmr],
IIf([tlsp].[last_order_qty_by_cstmr]>=[tlsp].[qb1]
And [tlsp].[last_order_qty_by_cstmr]<[tlsp].[qb2]
And [tlsp].[last_sell_prc_cstmr]<[tlsp].[up1],
[tlsp].[up1],
IIf([tlsp].[last_order_qty_by_cstmr]>=[tlsp].[qb2]
And [tlsp].[last_order_qty_by_cstmr]<[tlsp].[qb3]
And [tlsp].[last_sell_prc_cstmr]<[tlsp].[up2],
[tlsp].[up2],
IIf([tlsp].[last_order_qty_by_cstmr]>=[tlsp].[qb3]
And [tlsp].[last_sell_prc_cstmr]<[tlsp].[up3],
[tlsp].[up3])))) AS [proper price]
FROM tblLastSellPriceToCustomer_tmp AS tlsp;
Looking at that, it seems like you are missing the last false part.
Your statement:
I have marked the missing part
,MISSING FALSE.