I.T. Discussion Community!
-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

April Edition
Subscribe now! It's Free!
Enter your email:

   ► MB LobbyPascal and Delphi Coding BoardDelphi Single User Apps Topic   Print This     

Using SQL ???

Using SQL ??? in Delphi Single User Apps topic (part of our Pascal and Delphi Coding group).

Quick Search: Using SQL   Using SQL   
Mido
 (Inactive)
-- USA
Hi all,

I tried to use SQL Statement to found some records from 1 to 6 by using this code

ADOQuery1.close;
ADOQuery1.sql.clear;
ADOQuery1.sql.add ('select * from MyTable where FieldsName');
ADOQuery1.sql.add ('between '' + Edit1.text + ''and '' + Edit2.text + ''');
ADOQuery1.open;


But I got no resulte .... can you help please ?? Big Grin!
 Posted 19 years ago (Thread Starter)
Comment Quote
About Mido -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Email Not Verified!
Once email is verified, we will review and approve the account.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #2292, 1 replies
Thread Started 5/27/2001 7:34:00 PM
View Counter=1206
Last Reply Posted 5/29/2001 10:08:00 AM)
Location=-- USA 
Joined=19 years ago   MB Posts=21  
Most Recent Post
Scott Wehrly
Prestwood IT
 (Inactive)
Las Vegas, NV USA
The values 1 and 6 are numeric, yet your BETWEEN clause has double-quotes before and after the variable replacement, meaning that the resulting string will look like:

'Between '1' and '6''

If your field FieldsName is numeric, you wouldn't get any results comparing it to two strings. If either Edit1.text or Edit2.text is an empty string, you'd be testing on a null field value in the BETWEEN clause, which would result in no records found. In that case, you need to test Edit1.text and Edit2.text for empty strings, and add the appropriate conditional clause. For example:

If (Edit1.text = '') and (Edit2.text <> '') then
ADOQuery1.SQL.Add('< ' + Edit2.text)
else if (Edit1.text <> '') and (Edit2.text = '') then
ADOQuery1.SQL.Add('> ' + Edit1.text)
else if (Edit1.text <> '') and (Edit2.text <> '') then
ADOQuery1.SQL.Add('Between ' + Edit1.text + and ' + Edit2.text);



If your field FieldsName is a string, then the preferred way to embed quoted string values in a SQL statement is like this:

ADOQuery1.SQL.Add('Between ' + QuotedStr(Edit1.text) + ' and ' + QuotedStr(Edit2.text));

Of course, in that case, you should still do the conditional tests based on Edit1.text and Edit2.text, to avoid comparison to a null field value.
 Posted 19 years ago
Comment Quote
About Scott Wehrly -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #2303 (Level 1.1)  Reply to 2292
Thread Started 5/29/2001 10:08:00 AM
View Counter=2
Location=Las Vegas, NV USA 
Joined=18 years ago   MB Posts=442   KB Posts=19  

Revive Thread!

Add a comment to revive this old thread and make this archived thread more useful.

Write a Comment...
Full Editor
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P184A1
Enter key:
Icon: A Post    Thread    Idea    Important!    Cool    Sad    No    Yes    Includes a Link...   
Thread #2292 Counter
1206
Since 4/2/2008

Follow PrestwoodBoards on: 


©1995-2020 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech