Board index » delphi » SQL between two dates...

SQL between two dates...

Hi All !!

I've a silly problem but I don't know how to solve it...
I've a IBQuery on a form and I need to get the data from the table between
two dates which I enter in two TEdit components.
I do the following :
        IBQuery1.SQL.Text := 'select * from table1 where date >=
'+edit1.Text+' and date <= '+edit2.Text+' order by '+order;

and I get a conversion error.
Could anyone tell me how should I do the SQL if the date field is definied
as Date ?

thanks !
JLJ

 

Re:SQL between two dates...


Hi Phil,

thanks very much !  I works perfectly now ..

regards !
JLJ

Quote
"Phil Shrimpton" <p...@nospam.co.uk> wrote in message

news:MPG.18ebefefc04d7cd698973c@newsgroups.borland.com...
Quote
> In article <3e81d...@newsgroups.borland.com>, JLJ says...

> Hi,

> > I've a silly problem but I don't know how to solve it...

> >         IBQuery1.SQL.Text := 'select * from table1 where date >=
> > '+edit1.Text+' and date <= '+edit2.Text+' order by '+order;

> > and I get a conversion error.

> IBQuery1.SQL.Text := 'select * from table1 where date >= :param1 and
> date <= :param2 order by ' + order;
> IBQuery1.ParamByName('param1').AsDate := StrToDate(Edit1.text);
> IBQuery1.ParamByName('param2').AsDate := StrToDate(Edit2.text);

> Phil

Re:SQL between two dates...


In article <3e81d...@newsgroups.borland.com>, JLJ says...

Hi,

Quote
> I've a silly problem but I don't know how to solve it...

>         IBQuery1.SQL.Text := 'select * from table1 where date >=
> '+edit1.Text+' and date <= '+edit2.Text+' order by '+order;

> and I get a conversion error.

IBQuery1.SQL.Text := 'select * from table1 where date >= :param1 and
date <= :param2 order by ' + order;
IBQuery1.ParamByName('param1').AsDate := StrToDate(Edit1.text);
IBQuery1.ParamByName('param2').AsDate := StrToDate(Edit2.text);

Phil

Other Threads