Board index » delphi » SQL - from DATE to DATE

SQL - from DATE to DATE


2005-05-27 12:52:29 AM
delphi170
Hi!
I have a SQL like:
select * from mytable where mydate between (:from_date and :to_date)
I want to select *ALL* records less or equal than today. Can I do ?
Params[0].AsDate := 0
Params[1].AsDate := date
So far it seems to work fine. But I would like to be sure if this is a good way
to do it.
And what if I want to select *ALL* records ?
Params[0].AsDate := 0
Params[1].AsDate := ????
I'd like to avoid the use of OR clauses like:
select * from mytable where mydate between (:from_date and :to_date)
or :all = -1
Thanks!
Sergio
 
 

Re:SQL - from DATE to DATE

How about select * from mytable where mydate<=current_date?
Sergio Gonzalez writes:
Quote
Hi!
I have a SQL like:
select * from mytable where mydate between (:from_date and :to_date)

I want to select *ALL* records less or equal than today. Can I do ?
Params[0].AsDate := 0
Params[1].AsDate := date


 

Re:SQL - from DATE to DATE

"Quinn Wildman" <XXXX@XXXXX.COM>escribi?en el mensaje
Quote
How about select * from mytable where mydate<=current_date?
Thanks for replying Quinn!
Sometimes I need to ask for records between dates and sometimes I just want
to bring all the records.
I know that I can change the SQL statement, but I was wandering if I can do
that with my original SQL
Thanks again!
Sergio
 

Re:SQL - from DATE to DATE

Just use appropriately wide limits, e.g. to get everything
select data between years 1000 and 3000.
Quote
I have a SQL like:
select * from mytable where mydate between (:from_date and :to_date)

I want to select *ALL* records less or equal than today. Can I do ?
Params[0].AsDate := 0
Params[1].AsDate := date
Zero in TDate datatype means 30.12.1899, do you store older dates ?
Quote

So far it seems to work fine. But I would like to be sure if this is a good way to do it.
And what if I want to select *ALL* records ?
Params[0].AsDate := 0
Params[1].AsDate := ????

I'd like to avoid the use of OR clauses like:
select * from mytable where mydate between (:from_date and :to_date) or :all = -1
Just be aware that unnecessary using of index on big tables can decrease performance,
so the best is to use only those conditions in Where clause that you really need, i.e.
select * from mytable where mydate between (:from_date and :to_date)
select * from mytable where mydate < :to_date
select * from mytable ... to get all records.
Ivan