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
Database-Example.mdb
RichardAtkAsked:
Who is Participating?
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

0
PatHartmanCommented:
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.
0
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'
AND
UPDATE stk SET Qty = qty *0.85
WHERE type = 'Sales order'
    and status = 'F/O Only';
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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)
0
hnasrCommented:
Try:

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

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

Open in new window

/gustav
2

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.
0
Gustav BrockCIOCommented:
You are welcome!

/gustav
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.