Board index » delphi » Invalid use of keyword

Invalid use of keyword

D3.0
SQL Server 6.5

Anyone know why the heck I am getting "Invalid use of keyword. Token:
bad_data line number 1" on this SQL:

  Query1.Close;
  Query1.SQL.Clear;
  {throw all bad records into bad_data table}
  Query1.SQL.Add('insert bad_data ' +
                 '  (CompNo, LoginID, ProgName, JobNo, JobDesc,
StartStamp, EndStamp) ' +
                 'select CompNo, LoginID, ProgName, JobNo, JobDesc,
StartStamp, EndStamp from raw_data ' +
                 'where BadData = 1');
  Query1.ExecSQL;

_____________________
Mike E. Fullerton    | Mike's Killer Unix Page
Programmer / Analyst | http://www.spots.ab.ca/~cmatrix/UNIX.HTM

 

Re:Invalid use of keyword


Mike

I'd say your problem is two-fold.  First, you forgot the key word 'INTO
after the keyword INSERT. Secondly, you forgot the keyword VALUES
after the list of columns designated to receive the values. IOW, your
statement should read:

INSERT INTO BAD_DATA (CompNo, LoginID, ProgName, JobNo, JobDesc,
StartStamp, EndStamp)
VALUES (SELECT CompNo, LoginID, ProgName, JobNo, JobDesc, StartStamp,
EndStamp FROM RAW_DATA WHERE BadData = 1

Derek Davidson
Author of DK's Audit Components
Get a FREE copy from my web site at :
http://freespace.{*word*269}.net/d.davidson

(Remove the x to EMail me : der...@mksoft.com)

Re:Invalid use of keyword


Quote
Derek Davidson <derekx> wrote:
>I'd say your problem is two-fold.  First, you forgot the key word 'INTO
>after the keyword INSERT. Secondly, you forgot the keyword VALUES
>after the list of columns designated to receive the values. IOW, your
>statement should read:

>INSERT INTO BAD_DATA (CompNo, LoginID, ProgName, JobNo, JobDesc,
>StartStamp, EndStamp)
>VALUES (SELECT CompNo, LoginID, ProgName, JobNo, JobDesc, StartStamp,
>EndStamp FROM RAW_DATA WHERE BadData = 1

Thanks for the help but it still gives a similar error. (I pasted your
SQL into my code.)  Now it doesn't seem to like the INTO statement.
If I take it out I get exactly the same error.  
_____________________
Mike E. Fullerton    | Mike's Killer Unix Page
Programmer / Analyst | http://www.spots.ab.ca/~cmatrix/UNIX.HTM

Re:Invalid use of keyword


I believe the SQL should read as follows:

INSERT INTO BAD_DATA (CompNo, LoginID, ProgName, JobNo, JobDesc,
StartStamp, EndStamp)
VALUES (SELECT CompNo, LoginID, ProgName, JobNo, JobDesc, StartStamp,
EndStamp) FROM RAW_DATA WHERE BadData = 1

Derek just omitted the last right paren from his SQL.

Re:Invalid use of keyword


"Patrick W. O'Brien" <pobr...@seic.com> wrote:

Quote
>I believe the SQL should read as follows:

>INSERT INTO BAD_DATA (CompNo, LoginID, ProgName, JobNo, JobDesc,
>StartStamp, EndStamp)
>VALUES (SELECT CompNo, LoginID, ProgName, JobNo, JobDesc, StartStamp,
>EndStamp) FROM RAW_DATA WHERE BadData = 1

>Derek just omitted the last right paren from his SQL.

Yep I caught that, but the above SQL still gave me the error:

"Invalid use of keyword. Token: SELECT
 line number 1"

I did find the solution though.  My original SQL was fine, I had
"simply" neglected to add the line Query1.RequestLive:= False; before
I ran the query.

Also, SQL Server does not seem to like the INTO and VALUES bits.

_____________________
Mike E. Fullerton    | Mike's Killer Unix Page
Programmer / Analyst | http://www.spots.ab.ca/~cmatrix/UNIX.HTM

Re:Invalid use of keyword


Mike

First, my thanks to Patrick for jumping in and spotting my deliberate
error (hah - I wish).

I'm afraid my dodgy digits let me down.  There is a missing right
parenthese but it should be at the very end of the SQL statment (not
where Patrick had placed it).

Apologies for that

Derek Davidson
Author of DK's Audit Components
Get a FREE copy from my web site at :
http://freespace.{*word*269}.net/d.davidson

(Remove the x to EMail me : der...@mksoft.com)

Other Threads