Board index » delphi » SQL - Where am I wrong?

SQL - Where am I wrong?

When this query runs:

 with myque do begin
   close;
   databasename := privdir;
   sql.Clear;
   sql.add('SELECT B.JOURSEM AS DOW,B.HEURE AS HOURS,');
   sql.add('SUM(B.TRAF1+B.TRAF2+B.TRAF3+B.TRAF4+B.TRAF5+B.TRAF6+B.TRAF7+');
   sql.add('B.TRAF8+B.TRAF9+B.TRAF10+B.TRAF11+B.TRAF12) AS TRAFFIC,');
   sql.add('B.T_STAFF AS STAFF,C.TARGET AS TARGET ');
   sql.add('FROM '+privdir+'\'+TblSelected.TableName+' A,'+histfile+'
B,'+forecastfile+' C ');
   {on this next line "O" is capital o, not zero character}
   {this is the line generating the error}
   sql.add('WHERE A.DATEF = B.FDATE AND B.CODEOUV = "O" AND C.DATEF =
A.DATEF');
   sql.add('ORDER BY B.JOURSEM,B.HEURE');
   open;
 end;

I get: "Invalid use of keyword.
        Token: ?
        Line number: 5."
        <OK>

Many thanks in advance,

Daniel (dsto...@karabus.com)

 

Re:SQL - Where am I wrong?


CORRECTION:

Quote
Dan S. wrote in message ...
>When this query runs:

> with myque do begin
>   close;
>   databasename := privdir;
>   sql.Clear;
>   sql.add('SELECT B.JOURSEM AS DOW,B.HEURE AS HOURS,');
>   sql.add('SUM(B.TRAF1+B.TRAF2+B.TRAF3+B.TRAF4+B.TRAF5+B.TRAF6+B.TRAF7+');
>   sql.add('B.TRAF8+B.TRAF9+B.TRAF10+B.TRAF11+B.TRAF12) AS TRAFFIC,');
>   sql.add('B.T_STAFF AS STAFF,C.TARGET AS TARGET ');

{actually this is the line generating the error:->}
Quote
>   sql.add('FROM '+privdir+'\'+TblSelected.TableName+' A,'+histfile+'
>B,'+forecastfile+' C ');
>   {on this next line "O" is capital o, not zero character}
>   sql.add('WHERE A.DATEF = B.FDATE AND B.CODEOUV = "O" AND C.DATEF =
>A.DATEF');
>   sql.add('ORDER BY B.JOURSEM,B.HEURE');
>   open;
> end;

>I get: "Invalid use of keyword.
>        Token: ?
>        Line number: 5."
>        <OK>

>Many thanks in advance,

>Daniel (dsto...@karabus.com)

Re:SQL - Where am I wrong?


OK, I just solved it... :)
Read below:

Quote
Dan S. wrote in message ...
>CORRECTION:

>Dan S. wrote in message ...
>>When this query runs:

>> with myque do begin
>>   close;
>>   databasename := privdir;
>>   sql.Clear;
>>   sql.add('SELECT B.JOURSEM AS DOW,B.HEURE AS HOURS,');

sql.add('SUM(B.TRAF1+B.TRAF2+B.TRAF3+B.TRAF4+B.TRAF5+B.TRAF6+B.TRAF7+');

Quote
>>   sql.add('B.TRAF8+B.TRAF9+B.TRAF10+B.TRAF11+B.TRAF12) AS TRAFFIC,');
>>   sql.add('B.T_STAFF AS STAFF,C.TARGET AS TARGET ');

>{actually this is the line generating the error:->}

>>   sql.add('FROM '+privdir+'\'+TblSelected.TableName+' A,'+histfile+'
>>B,'+forecastfile+' C ');

Here I am using file names with full path and extension. Therefore, I should
have enclosed the file path and name with single or double quotes... like
this:

   sql.add('FROM "c:\mydir\myfile.dbf" A,"c:\mydir1\myfile1.dbf"
B,"c:\mydir2\myfile2.dbf" C ');

That was it, much noise for nothing at all. :)

Quote

>>   {on this next line "O" is capital o, not zero character}
>>   sql.add('WHERE A.DATEF = B.FDATE AND B.CODEOUV = "O" AND C.DATEF =
>>A.DATEF');
>>   sql.add('ORDER BY B.JOURSEM,B.HEURE');
>>   open;
>> end;

>>I get: "Invalid use of keyword.
>>        Token: ?
>>        Line number: 5."
>>        <OK>

>>Many thanks in advance,

>>Daniel (dsto...@karabus.com)

Re:SQL - Where am I wrong?


On Wed, 25 Aug 1999 16:53:48 -0400, "Dan S." <m...@karabus.deletethis.com>
wrote:

[...]

Quote
>Here I am using file names with full path and extension. Therefore, I should
>have enclosed the file path and name with single or double quotes... like
>this:

>   sql.add('FROM "c:\mydir\myfile.dbf" A,"c:\mydir1\myfile1.dbf"
>B,"c:\mydir2\myfile2.dbf" C ');

>That was it, much noise for nothing at all. :)

One way to visually verify dynamically built SQL (for the future,
obviuously <grin>) is the ShowMessage. Pass the Text property of the TQuery
as the parameter for ShowMessage.

  ShowMessage(Query1.Text);

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Steve Koterski               "Health nuts are going to feel stupid someday
Felton, CA                   lying in hospitals dying of nothing."
                                                              -- Redd Foxx

Re:SQL - Where am I wrong?


Ain't that cool?
Thanks for the tip :)
Quote
Steve Koterski wrote in message <37cd890c.32359...@news.gte.net>...
>On Wed, 25 Aug 1999 16:53:48 -0400, "Dan S." <m...@karabus.deletethis.com>
>wrote:

>[...]
>One way to visually verify dynamically built SQL (for the future,
>obviuously <grin>) is the ShowMessage. Pass the Text property of the TQuery
>as the parameter for ShowMessage.

>  ShowMessage(Query1.Text);

>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
>Steve Koterski               "Health nuts are going to feel stupid someday
>Felton, CA                   lying in hospitals dying of nothing."
>                                                              -- Redd Foxx

Other Threads