Jump to content
Fórum Script Brasil
  • 0

Syntax MySQL + Delphi dando erro UPDATE, WHERE


Question

I have a code with Delphi + MySQL Server 8.0 Community version. It runs well. I am trying to do an UPDATE like in the code to follow. I tried many alternatives and always get the error message:

 

Error #42000 You have na error in your SQL syntax check the manual that corresponds to your MySQL server version for the right syntax to use near “WHERE LOGIN=’[email protected]’ AND DATEREGISTER=’2021-05-03 17:58:20’’ at line 1

 

Could you please tell me what is wrong in the syntax ?

 

 

       uniMainModule.USERS.IndexFieldNames:='DATEREGISTER';

       Nregisteredusers:=uniMainModule.USERS.RecordCount;

       NDATE: = unimainmodule.USERS.fieldByname('DATEREGISTER').AsDateTime;

       NUSERX: = unimainmodule.USERS.fieldByname('LOGIN').AsString;

       NSITE: = unimainmodule.USERS.fieldByname('SITEVISITS').AsInteger;

       ASSE:= unimainmodule.USERS.fieldByname('ASSESSMENT').AsInteger;

       AddNewUser := TMyQuery.Create(nil);

        try

   AddNewUser.Connection := uniMainModule.MyConnection;

    AddNewUser.SQL.Clear;

 

 AddNewUser.SQL.text: ='UPDATE USERS SET SITEVISITS = :NSITE, ASSESSMENT = :ASSE,' +

      ' WHERE LOGIN=: NUSERX AND DATEREGISTER=: NDATE';

 AddNewUser.Params.ParamByName('NSITE').AsInteger := NSITE;

 AddNewUser.Params.ParamByName('ASSE').AsInteger := ASSE;

 AddNewUser.Params.ParamByName('NUSERX').AsString := NUSERX;

 

 AddNewUser.ExecSQL;

      finally

               FreeAndNil(AddNewUser)

      end;

Link to post
Share on other sites

1 answer to this question

Recommended Posts

  • 0

' WHERE LOGIN=: NUSERX AND DATEREGISTER=: NDATE';

' WHERE LOGIN= :NUSERX AND DATEREGISTER= :NDATE';

' WHERE LOGIN= ' + '''' +  NUSERX + '''' + 'AND DATEREGISTER= ' + '''' + NDATE + ''''';

“WHERE LOGIN='[email protected] 'AND DATEREGISTER =' 2021-05-03 17:58:20 ''

Take care of the =: because you may be passing a parameter and not assigning the value of a variable

If parameter is  = : (separated by a blank space)

If it is the value of a variable it is only =

also note that the variable's flower must be preceded by an apostrophe (before and after)

hug

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      149264
    • Total Posts
      645605
×
×
  • Create New...