IIF statement help

craig198101

New Member
Joined
Mar 16, 2016
Messages
5
Hi all,

I am trying to create a query to append records into a an existing table. I need the query to include the following IIF statement:
IF “REMAINING QTY” is less than Oracle FIFO “TxnQty”
THEN
1. Copy original Oracle FIFO record to INSERT brand new Oracle FIFO record with “TxnQty” = “TxnQty” - “REMAINING QTY” and “StatusCode” = ‘D’
2. UPDATE original Oracle FIFO “TxnQty” = “REMAINING QTY”, leaving “StatusCode” = ‘N’
END IF

Tables:
FIFOCMSData holds TxnQty and StatusCode
QTYFIFOWH holds REMAINING QTY and TxnQty1

I have managed to do part one with two IIF:
1.TxnQty: IIf([SumOfREMAINING QTY]<[TxnQty1],[TxnQty1]-[SumOfREMAINING QTY],"0")
2.StatusCode: IIf([SumOfREMAINING QTY]<[TxnQty1],"D","N")

Any ideas how to either do one nested iif(with example) or best way to create the above would be a massive help.

Big thank you in advance
 

Some videos you may like

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,793
Office Version
  1. 2019
Platform
  1. Windows
Hi,
what are the primary keys in the tables? It will be hard to write any queries without that information.
 

craig198101

New Member
Joined
Mar 16, 2016
Messages
5
Thank you for the reply the primary keys are FIFOCMSData: ReceiptSupplement(invoice number) and QTYFIFOWH: Invoice Number
 

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,793
Office Version
  1. 2019
Platform
  1. Windows
Hmm. Actually it can't be done because you want to copy a record:
1. Copy original Oracle FIFO record to INSERT brand new Oracle FIFO record with “TxnQty” = “TxnQty” - “REMAINING QTY” and “StatusCode” = ‘D’

But if you do that you will be copying the primary key as part of the new record. And you cannot have two records with the same primary key.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,469
Messages
5,596,329
Members
414,055
Latest member
mcarduner

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top