Re: SQL syntax help needed

From: Bjrn Lundin <bjorn(dot)lundin(at)swipnet(dot)se>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: SQL syntax help needed
Date: 2002-01-04 13:25:56
Message-ID: 20020104142556.056e376a.bjorn.lundin@swipnet.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, 3 Jan 2002 16:07:30 -0800
"Chris Sypolt" <csypolt(at)onlinemetals(dot)com> wrote:

> Sorry - wasn't thinking.
Well it happens to me too...

This migth do it..

Select orders.*, shipments.*
from orders,shipments
where orders.orderid = shipments.orderid
and ShipDate(orders.orderdate) <= shipments.shipdate;

You then need a function (in plpg/Sql) to get the correct shipdate for an order.
(In ada)

function Shipdate(aDate : in Date) return date is
begin
case Weekday(aDate) is
when Mon..Fri => return aDate;
when Sat => return aDate + 1;
when Sun => return aDate + 2;
end case;
end ShipDate;

You also need a function Weekday, to determine what day of week a given date is.
Zeller's Congruence is your friend here.
Look at John English's 'Ada 95: the Craft of Object-Oriented Programming' chapter 4
(http://www.it.brighton.uk/staff/je/adacraft/ch04.htm)

That shouldn't be too hard to translate to plpg/Sql.

There is perhaps easier ways to do this, but this is what I've come up with.

/Björn

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bjrn Lundin 2002-01-04 13:28:05 Re: SQL syntax help needed
Previous Message Stephan Szabo 2002-01-04 08:19:53 Re: maintaining a field for every UPDATION.