Re: HELP - How to Do this Query?
Posted in 1997
Sujit Pal a 'crit dans le message <62qnti$fu7@cssun.mathcs.emory.edu>...
>Yan/Dragi
>
>How about this query?
>
>SELECT * FROM table
>WHERE (datecol + 10) >= '97/10/10'
>AND (datecol - 10) <= '97/10/10'>
Very bad option, as it does not use the possible index on datecol (so the
where clause may be quite long).
The following should be prefered:
SELECT * FROM TABLE
WHERE datecol BETWEEN MDY(10,10,1997)-10 AND MDY(10,10,1997)+10
or when bounds must not be included:
SELECT * FROM TABLE
WHERE datecol > MDY(10,10,1997) - 10
AND datecol < MDY(10,10,1997) + 10
or if datecol has time precision and you need time precision for the bounds:
SELECT * FROM TABLE
WHERE datecol > DATETIME(1997-10-10 12:00)YEAR TO MINUTE - 10 UNITS DAY
AND datecol < DATETIME(1997-10-10 12:00)YEAR TO MINUTE - 10 UNITS DAY
And also, you may also precompute the bounds to reduce the SQL code.
>Make sure your DBDATE environment variable is set (in your case YMD2/).
Using the "MDY()" function (or the "DATETIME(1997-10-10)YEAR TO DAY"
constant syntax) preserves you from locales dependency.