syntax error in sql statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kkshansid
    New Member
    • Oct 2008
    • 232

    syntax error in sql statement

    Code:
     db.Execute "INSERT INTO TAXDET (ECODE, totsaving,OTHERSAV) VALUES('" & ecode & "'," & totsaving & "," & OTHERSAV & ")"
    gives error
    syntax error in sql statement
    and in debug mode it shows totsaving =null and
    OTHERSAV =null
    kindly help me to correct error
    thanx in adv
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    On my way out the door to work, thus, only a very quick look and answer:

    You really haven't provided enough of the code to help.
    What I do is build the string first so that you can troubleshoot the resolved string. Something along the lines of:

    Code:
    strSQL = "INSERT INTO TAXDET (ECODE, totsaving,OTHERSAV) VALUES('" & ecode & "'," & totsaving & "," & OTHERSAV & ")"
    Debug.Print strSQL
    db.Execute  strSQL
    Now you can look in the debug window and see what your string issue is...
    Last edited by zmbd; Jan 24 '13, 06:33 PM. Reason: [NeoPa{Fixed mistype from rush.}] [Z{Thank You Neopa!}]

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32656

      #3
      Your string issue is that you have no values for either of these fields in your SQL command. If you want Null then you have to use the text "Null", and if you want zero then "0". Leaving it empty, as you have done, will throw an error (such as you've seen).

      Comment

      Working...