Problem with SQL Syntax

Posted on 2007-10-11
Last Modified: 2010-08-05
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?
Question by:ST3VO
    LVL 19

    Expert Comment

    var SomeVariable: string;
     SomeVariable := 'AD13324';
     Memo1.Lines.Add(Format('SELECT * From products WHERE AccountID = '%s', [SomeVariable]));

    Author Comment


    I'm trying this:

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

    and get an error: Invalid Character '%'

    Any ideas why?
    LVL 19

    Accepted Solution


    should have been:

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

    LVL 6

    Expert Comment

    Try this
    someVariable := QuotedStr('AD13324');
    Memo1.Lines.Add('SELECT * From products WHERE AccountID='+SomeVariable);

    Author Comment

    Great!!! Thanks! Perfect :o)


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
    Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now