Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 168
  • Last Modified:

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?
0
ST3VO
Asked:
ST3VO
  • 2
  • 2
1 Solution
 
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
 
MerijnBSr. Software EngineerCommented:
oops!

should have been:

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


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

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now