Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO & SQL in procedures

Status
Not open for further replies.

PaidtheUmpire

Programmer
Jan 4, 2004
105
AU
I am currently using Delphi 7's ADO database connection system, in my project and I am wondering how to do the following SQL query in the middle of a button click procedure.

SELECT Client_Reference_Number
FROM SimCard_Details
WHERE IMSI_Number = IMSI AND Active = Yes;
// The only variable here given from the ButtonClick procedure is 'IMSI'

This should give a total of ONE result but i am unsure how to get the resulting value into the 'CRN' variable.

 
This should work:

With ADOQuery1 do begin
SQL.Clear;
SQL.Add('SELECT Client_Reference_Number');
SQL.Add('FROM SimCard_Details');
SQL.Add(Format('WHERE IMSI_Number = %d AND Active = Yes;',[IMSI]));
Open;
try
First;
CRN := Fields[0].asInteger;
finally
Close;
end;
end;
 
Thanks for the code, but there is a problem when i run it...

it says ...

Format '%d' is invalid or incompatable

so anymore ideas?
 
Use a parametrized query

etc..

SQL.Add('WHERE IMSI_Number =:IMSI_NUBER AND Active = Yes');

ParamByName('IMSI_NUBER').AsString := MyEntryValue;




Steven van Els
SAvanEls@cq-link.sr
 
About the %d, the "Format" function expects the IMSI to be an Integer. If it is a string, put %s or a float, %f. (See "Format function" in Delphi Help files).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top