Joe Celko (jcelko212@earthlink.net) writes:
[quoted text, click to view] >>> ... when I have an open time interval, I rather use '99991231' than
> CURRENT_TIMESTAMP. <<
>
> If I have an event that is still in progress, such as checking into a
> hotel, then the only real knowledge I have is that Mr. X is still here,
> right now. I can figure out his current bill, etc. in a simple VIEW.
> The NULL is easy to spot and to handle for this purpose.
Agreed, I don't question that part. What I meant to say is that
SELECT *
FROM tbl
WHERE coalesce(enddate, CURRENT_TIMESTAMP) > @stopdate
could give in correct result, if both @stopdate and endate are in
the future. (Say for instance that tbl holds contracts that can be
open-ended, but also have future date at which they expire. Thus
I would rather write that as:
SELECT *
FROM tbl
WHERE coalesce(enddate, '99991231') > @stopdate
(Note: the above is for performance reasons better written as
enddate IS NULL OR enddate > @stopdate in SQL Server.)
Using special values to mean something is certainly not good practice,
because if you forgot if you used 99991231 or 21010101 or whatever, you
may get the wrong result.
[quoted text, click to view] > If you use a dummy date, then you need to be sure that:
Agreed on all your points.
I have to admit that I have committed the sin at least once. I have
a table cross-currency pairs, and there is a column fixedfrom which
tells you from which date the currency rate for this pair has been
fixed. In practice there are three(*) possible values: NULL (the rate
is not fixed), 19990101 DEM/EUR, ITL/EUR etc and 17530101 for
SEK/SEK, USD/USD etc. In this case NULL was not available to mean
"has always been". (Of course, I could have added an extra column
which would have specified that fixedfrom had any meaning at all,
but was less appetizing. Even if that is the way it looks in the GUI.)
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server SP3 at