Recent

Author Topic: SQL syntax error  (Read 3825 times)

jablalooz

  • Newbie
  • Posts: 2
SQL syntax error
« on: February 15, 2018, 05:23:54 pm »
Hello
I want to update the values of column values in a table when the condition is met in the other column, but the problem is that when using this term

TSQLQuery.SQL.Text:= 'SET @num: = 0; UPDATE MyTable SET ID = @num: = (@ num + 1) where ID_Name = 1;';
TSQLQuery.ExecSQL;
Trans.Commit;

This is due to an error in the SQL statement

win10 64
lazarus 1.8.0
mysql5.5

GAN

  • Sr. Member
  • ****
  • Posts: 370
Re: SQL syntax error
« Reply #1 on: February 15, 2018, 09:19:17 pm »
Use ExecuteDirect from your connection instead TSQLQuery.ExecSQL. Check the wiki: http://wiki.lazarus.freepascal.org/Working_With_TSQLQuery#Query_with_Format_function
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

jablalooz

  • Newbie
  • Posts: 2
Re: SQL syntax error
« Reply #2 on: February 15, 2018, 10:22:13 pm »
Thanks for the answer
I used it, but the problem is still the same
This statement

SET  @num := 0;
UPDATE MyTable SET ID = @num := (@num+1) where ID_Name =1;

 works in MySQL effectively, but when in Lazarus the error is due to not recognizing  tokin :@ num

GAN

  • Sr. Member
  • ****
  • Posts: 370
Re: SQL syntax error
« Reply #3 on: February 15, 2018, 10:36:26 pm »
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

egsuh

  • Hero Member
  • *****
  • Posts: 1291
Re: SQL syntax error
« Reply #4 on: February 18, 2018, 12:05:44 am »
I don't know about MS-SQL, but TSQLQuery seems to take only one command. Try TSQLScript instead.

 

TinyPortal © 2005-2018