Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

syntax error in FROM clause

Posted on 2001-08-25
4
Medium Priority
?
411 Views
Last Modified: 2010-04-06
hi,

i have a combo filled via ado's gettablenames
and onchange event of combo looks like:

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
AdoTable1.Active := False;
AdoTable1.TableName := Combobox1.text;
DbMemo1.Datafield := Combobox1.Text + ' Code';
DbMemo2.Datafield := Combobox1.Text + ' Title';
AdoTable1.Active := True;
etc...


problem arises when a table name is stupid like
c++
 or
tablename with spaces
etc..

im getting a "syntax error in FROM clause" error .

i understand i could normally use quotes in a
sql statement to get around these sort of problems but
i dont know how to do it for this scenario ..is there a quick fix i can do for this?

as a last resort i can change the tablenames but id rather not ;-)

Regards Barry
0
Comment
Question by:inthe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 400 total points
ID: 6424710
just doublequote the tablename like "c++"

AdoTable1.TableName := '"'+Combobox1.text+'"';

0
 
LVL 17

Author Comment

by:inthe
ID: 6424736
hi meikl,
i tried that one first ;-)
it gives syntax error in query error.

but you lead me to right idea:

AdoTable1.TableName := '['+Combobox1.text+']';

i never tried that one i was trying using "" and ()..

cheers Barry

while im here another piece of code looks like :

  AdoQuery1.SQL.Clear;
  AdoQuery1.SQL.Add
  ('SELECT * FROM '+combobox1.text+' WHERE '+Edit1.Text+' IN '+combobox1.text+'.['+combobox1.text + ' Code]');
  AdoTable1.DisableControls;
  edit1.text := AdoQuery1.SQL.Text;
   Adoquery1.ExecSQL;
  ADOTable1.EnableControls;

a bit messy i know but the sql ends up as:

SELECT * FROM Application WHERE shell IN Application.[Application Code]

which produces the following exact error:

in operator without () in query expression
 'shell IN Application.[Application Code]'

do you know what the sql should end up like for that to work?

i did have it working on simple tablenames but again when i came to a table with a break in name etc it died so i had to start the []()"" stuff :-)
0
 
LVL 17

Author Comment

by:inthe
ID: 6424743
just to clarify the [] did work to solve original problem:

AdoTable1.TableName := '['+Combobox1.text+']';


0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6424835
oh, this jetsql-syntax :-(

well, thanks for the points, :-))
glad to adviced you to the right way,
even i was not correct by this chars []

meikl ;-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

719 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