Access update Qry

Hi I would like to be able to update the attached access database ad-hoc with an update qry but not at all sure where to start.
I want the database to multiply the Qty field as below replacing the value in the qty field with the new calc.

Only when type =  Sales order  
if Items status name = F/O Only  * Qty field by 0.85 (rounded) up to the nearest whole number
If item status name = open  * Qty field by 0.95 (rounded ) up to the nearest whole number
The qty field remains as is for anything not matching above
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
something like this:
update yourtable
    set Qty = ceiling ( Qty  * iif( status = 'F/O Only' ; 0.85 , 0.95 ) )
  where type = 'Sales order'
    and status in ( 'F/O Only', 'Open' )

Open in new window

the ceiling function needs to be implemented:
Public function  Ceiling(ByVal X As Double) As Double

Ceiling = Int(X) - (X - Int(X) > 0)

End Function

Open in new window

Rather than updating the table, calculations like this should be performed on the fly in queries.  Storing the values violated second and/or third normal form.
RichardAtkAuthor Commented:
Thanks I have used this and it works but needs to expand a little as below  

UPDATE stk SET Qty = qty *0.95
WHERE type = 'Sales order'
    and status = 'Open'

What I need to do is ( not sure how to get the and bit working also to run 2 updates.
and needs to be all rounded up to the nearest whole number
UPDATE stk SET Qty = qty *0.95
WHERE type = 'Sales order'
    and status = 'Open'
UPDATE stk SET Qty = qty *0.85
WHERE type = 'Sales order'
    and status = 'F/O Only';
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
you cannot combine 2 updates with a AND
only the syntax way I suggested ( or run them 1 after the other)
Hamed NasrRetired IT ProfessionalCommented:

UPDATE [stk final tbl] SET [stk final tbl].qty = Switch([item staus name]='F/O Only' AND [type] = 'Sales order',Sgn([qty])*Int(Abs([qty])*0.85+0.5),[item staus name]='open' AND [type] = 'Sales order',Sgn([qty])*Int(Abs([qty])*0.95+0.5),True,[qty]);

Open in new window

Gustav BrockCIOCommented:
It doesn't have to be that complicated (corrected typo in field name):
    [stk final tbl]
    qty = -Int(-qty * IIf([item status name] = 'open', 0.95, 0.85))
    [type] = 'sales order'
    [item status name] In ('open', 'F/O Only')

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RichardAtkAuthor Commented:
Brilliant simple and concise exactly what I was after works  perfectly many thanks.
Gustav BrockCIOCommented:
You are welcome!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.