Re: SQL syntax help needed - Mailing list pgsql-sql

From Björn Lundin
Subject Re: SQL syntax help needed
Date
Msg-id 20020104142556.056e376a.bjorn.lundin@swipnet.se
Whole thread Raw
List pgsql-sql
On Thu, 3 Jan 2002 16:07:30 -0800
"Chris Sypolt" <csypolt@onlinemetals.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


pgsql-sql by date:

Previous
From: "Chris Sypolt"
Date:
Subject: Re: SQL syntax help needed
Next
From: Björn Lundin
Date:
Subject: Re: SQL syntax help needed