Re: A "days at" query

From: Theo Peterbroers <peterbroers_at_floron.leidenuniv.nl>
Date: 31 Jan 2002 00:20:33 -0800
Message-ID: <39bb2c10.0201310020.51292f6c_at_posting.google.com>


eel_at_javabox.com (Eel) wrote in message news:<a62a408.0201301851.2cfba420_at_posting.google.com>...
> Hi,

< snip >
> "create table transactions
> date_in DATE,
> date_out DATE"
>
> I can do something like "select date_in, date_out, date_out - date_in
> as da from transactions"
>
> This works, but I have a more complex requirement which is that in
> cases where date_out = null, ie still at a location, I want to use
> current_date - date_in instead of date_out - date_in. Is there a way
> to do this? I keep getting syntax errors.

SELECT date_in,date_out,date_out-date_in AS da FROM transactions
WHERE date_out IS NOT NULL
UNION ALL
SELECT date_in,date_out,date()AS da
FROM transactions
WHERE date_out IS NOT NULL

I'm not entirely sure about date(): maybe it's called today(). Received on Thu Jan 31 2002 - 09:20:33 CET

Original text of this message