Problem with SQL Syntax

Hi all,

I need some help with some SQL Sytax as I am getting errors.

Here is the code:

Memo1.Lines.Add('SELECT * From products WHERE AccountID='+SomeVariable);

This is what it's adding right now: SELECT * From products WHERE AccountID='+SomeVariable+' ,which is wrong.

I need it to add the the Memo something like this:

SELECT * From products WHERE AccountID='AD13324'

Can anyone help please?
ST3VOAsked:
Who is Participating?
 
MerijnBSr. Software EngineerCommented:
oops!

should have been:

 Memo1.Lines.Add(Format('SELECT * From products WHERE AccountID=''%s''',[TheField]));


sorry!
0
 
MerijnBSr. Software EngineerCommented:
var SomeVariable: string;
begin
 SomeVariable := 'AD13324';
 Memo1.Lines.Add(Format('SELECT * From products WHERE AccountID = '%s', [SomeVariable]));
end;
0
 
ST3VOAuthor Commented:
Hmmm

I'm trying this:

 Memo1.Lines.Add(Format('SELECT * From products WHERE AccountID='%s',[TheField]));

and get an error: Invalid Character '%'

Any ideas why?
0
 
bokistCommented:
Try this
someVariable := QuotedStr('AD13324');
Memo1.Lines.Add('SELECT * From products WHERE AccountID='+SomeVariable);
0
 
ST3VOAuthor Commented:
Great!!! Thanks! Perfect :o)

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.