Re: Select Maths

From: "Phillip Smith" <phillips(at)weatherbeeta(dot)com(dot)au>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Select Maths
Date: 2006-07-10 07:21:53
Message-ID: 000001c6a3f1$84cf1ed0$9b0014ac@ITPhil
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Beautiful - Works a treat. Thanks Aaron.

A follow-on problem now. I have the below column in the select, but I need
to validate the value across all 3 rules - I need to assign it to a
variable!!

Example - my pqty function calculates a value less than the suppliers
minimum order qty (and therefore fails the first CASE below), I need to set
the column to a new value (stock.purchase_unit) - That's all OK. But I need
to check this new value against the remaining 2 CASE's.

<SNIP>

CASE WHEN pqty(stock.code) < stock.purchase_unit THEN stock.purchase_unit

--^^^-- Check that our suggested purchase qty is greater than
then suppliers minimum order qty

WHEN MOD(pqty(stock.code), stock.box_qty) > 0 THEN stock.box_qty *
ROUND(CAST(pqty(stock.code) AS DOUBLE PRECISION) / stock.box_qty)

--^^^-- Check that our suggested purchase qty is a multiple of
the box qty

WHEN pqty(stock.code) < (urate(stock.code) * creditors.review_cycle)
THEN urate(stock.code) * creditors.review_cycle

--^^^-- Check that our suggested purchase qty is greater than
our Usage Rate x Creditor Review Cycle

END AS "pqty",

<SNIP>

Thanks again for all your help guys,

-p

-----Original Message-----
From: aaron(dot)bono(at)gmail(dot)com [mailto:aaron(dot)bono(at)gmail(dot)com] On Behalf Of Aaron
Bono
Sent: Friday, 7 July 2006 18:37
To: Phillip Smith
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: [SQL] Select Maths

On 7/7/06, Phillip Smith <phillips(at)weatherbeeta(dot)com(dot)au> wrote:

Same SELECT query as before, different area of it. I have a function that
calculates the recommended purchase order quantity for a stock item based
off various other values and functions:

pqty(stock.code) AS "pqty"

This needs to be rounded up / down to the nearest multiple of the purchase
unit quantity for that product - It's Friday afternoon and my head has
refused to help me work out the maths all afternoon!

Example:

Pqty = 60

Purchase Unit = 25

Pqty needs to be rounded down to 50.

I guess I'm also asking if I should do this in the Pqty function or in the
SELECT query to optimize the result?

select 25 * round(cast(60 as double precision) / 25)

*******************Confidentiality and Privilege Notice*******************

The material contained in this message is privileged and confidential to
the addressee. If you are not the addressee indicated in this message or
responsible for delivery of the message to such person, you may not copy
or deliver this message to anyone, and you should destroy it and kindly
notify the sender by reply email.

Information in this message that does not relate to the official business
of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta.
Weatherbeeta, its employees, contractors or associates shall not be liable
for direct, indirect or consequential loss arising from transmission of this
message or any attachments

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message T E Schmitz 2006-07-10 11:02:06 Re: SELECT substring with regex
Previous Message Emils 2006-07-10 05:11:47 Re: SELECT substring with regex