Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 28th, 2006, 3:05 AM   #1
wernervt
Newbie
 
Join Date: Mar 2006
Posts: 10
Rep Power: 0 wernervt is on a distinguished road
Using Sql and BDE

I would like to know how do i use a simple sql statement to to select data from the contents of 1 edit box to another edit box?

For example
I have a database called query and i would like to filter dates on the table, but i want the sql statement to look in edit 1 box what is the start date and then in edit 2 box what is the end date, and then filter it.

Here is an example of my code wich dosent work:

SELECT * FROM Query
WHERE QOUTEDATE >= :edit1
AND QOUTEDATE <= :edit2
AND RepName = :edit3

Thank You
Werner
wernervt is offline   Reply With Quote
Old May 5th, 2006, 6:23 AM   #2
Christo
Newbie
 
Christo's Avatar
 
Join Date: May 2006
Location: South-Africa
Posts: 8
Rep Power: 0 Christo is on a distinguished road
Send a message via MSN to Christo Send a message via Yahoo to Christo
Well you can try this, I couldn't figure it out myself but i went and asked around, Try this :

procedure TForm14.Button17Click(Sender: TObject);
begin
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add('SELECT * FROM Query WHERE QOUTEDATE BETWEEN ' +
edit1.Text + ' AND ' + edit2.Text + ' AND RepName = ' + edit3.Text);
Query1.Open;
end;


However there could be a problem with this if the database server does not recognize the date format from the edit boxes. In this case the workaround could be:

procedure TForm14.Button17Click(Sender: TObject);
begin
Query1.Close;
Query1.ParamByName('qoutedate1').AsDateTime := StrToDateTime(edit1.Text);
Query1.ParamByName('qoutedate2').AsDateTime := StrToDateTime(edit2.Text);
Query1.ParamByName('repname').AsString := edit3.Text;
Query1.Prepare();
query1.Open;
end;
__________________
Forgive me if I ask Stupid Questions, to you it may be stupid but to me it's something I want to find out! So Please bear with me and help me out! Thank you!
Christo is offline   Reply With Quote
Old May 5th, 2006, 3:37 PM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
If you're going to use SQL, make sure the dates are in the international 'YYYY-MM-DD' format.

Oh, and both of you, please use [code] tags.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:40 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC