UPDATE query gives Incorrect Syntax error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris Kennedy

    UPDATE query gives Incorrect Syntax error

    Hi all

    I'm running SQL Server 2005 Express Edition.
    One database
    One table called Sites
    Fields as follows:
    id (bigint, Identity, Primary Key)
    SiteName (varchar(50), allows nulls)
    Generation (float)
    LastUpdated (varchar(50), allows nulls)

    At present there are only three records in this table.

    My VB application connects via ODBC (using Named Pipes) no problems.
    SELECT queries run as expected and return appropriate records.
    When I run an UPDATE query like this one:
    UPDATE Sites SET (Generation = 44) WHERE (SiteName = 'Test')
    I get the following error:
    -2147217900 [Microsoft][ODBC SQL Server Driver][SQL
    Server]Incorrect syntax near '26'.

    Now the funny thing is that the field LastUpdated did contain
    '26/08/2008' but I have changed the field value and still get the same
    error message.
    Restarting SQL Server does not fix the problem nor does rebooting the
    machine.
    The query works perfectly from inside the Management Studio but not
    via ODBC.
    The ODBC connection is fine so I don't think this is a security/
    permissions problem.

    I'd appreciate some advice.

    Chris
  • Erland Sommarskog

    #2
    Re: UPDATE query gives Incorrect Syntax error

    Chris Kennedy (chrisk@clarke-energy.com) writes:
    I'm running SQL Server 2005 Express Edition.
    One database
    One table called Sites
    Fields as follows:
    id (bigint, Identity, Primary Key)
    SiteName (varchar(50), allows nulls)
    Generation (float)
    LastUpdated (varchar(50), allows nulls)
    >
    At present there are only three records in this table.
    >
    My VB application connects via ODBC (using Named Pipes) no problems.
    SELECT queries run as expected and return appropriate records.
    When I run an UPDATE query like this one:
    UPDATE Sites SET (Generation = 44) WHERE (SiteName = 'Test')
    I get the following error:
    -2147217900 [Microsoft][ODBC SQL Server Driver][SQL
    Server]Incorrect syntax near '26'.
    >
    Now the funny thing is that the field LastUpdated did contain
    '26/08/2008' but I have changed the field value and still get the same
    error message.
    Restarting SQL Server does not fix the problem nor does rebooting the
    machine.
    The query works perfectly from inside the Management Studio but not
    via ODBC.
    The ODBC connection is fine so I don't think this is a security/
    permissions problem.
    Interesting. Are there any triggers on the table?

    If there is not, my suspicion that you are somehow mistaken about the
    statement that causes the error. Using Profiler and including the events
    Error:Exception and Error:UserMessa ge can be a good idea.


    --
    Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se

    Books Online for SQL Server 2005 at

    Books Online for SQL Server 2000 at

    Comment

    • Chris Kennedy

      #3
      Re: UPDATE query gives Incorrect Syntax error

      On Aug 26, 3:56 pm, Erland Sommarskog <esq...@sommars kog.sewrote:
      >
      Interesting. Are there any triggers on the table?
      >
      If there is not, my suspicion that you are somehow mistaken about the
      statement that causes the error. Using Profiler and including the events
      Error:Exception and Error:UserMessa ge can be a good idea.
      >
      --
      Erland Sommarskog, SQL Server MVP, esq...@sommarsk og.se
      >
      Books Online for SQL Server 2005 athttp://www.microsoft.c om/technet/prodtechnol/sql/2005/downloads/books...
      Books Online for SQL Server 2000 athttp://www.microsoft.c om/sql/prodinfo/previousversion s/books.mspx- Hide quoted text -
      >
      - Show quoted text -
      Hi Erland

      No - no triggers on the table.
      Indeed it was just a case of creating a new database, add a table and
      add fields.
      I suspect you may be right about the statement that is causing the
      error message however the UPDATE query is the only statement I am
      trying to run.
      Is it possible that a previous query has somehow become trapped and is
      being retried by SQL Server when I am trying to run my query?
      I'll investigate the use of the Profiler to try and determine exactly
      what is going on.
      Can you point me to an online tutorial for the Profiler as the MSDN
      wasn't that easy to follow?

      Chris

      Comment

      • Erland Sommarskog

        #4
        Re: UPDATE query gives Incorrect Syntax error

        Chris Kennedy (chrisk@clarke-energy.com) writes:
        No - no triggers on the table.
        Indeed it was just a case of creating a new database, add a table and
        add fields.
        I suspect you may be right about the statement that is causing the
        error message however the UPDATE query is the only statement I am
        trying to run.
        Is it possible that a previous query has somehow become trapped and is
        being retried by SQL Server when I am trying to run my query?

        Rather something the client API is doing behind your back.
        I'll investigate the use of the Profiler to try and determine exactly
        what is going on.
        Can you point me to an online tutorial for the Profiler as the MSDN
        wasn't that easy to follow?
        It's not that difficult. Start Profiler, select New Trace complete the
        Connection Dialog. In the dialog that comes up, click the Events Selection
        tab. Down to the right there is a check box, Show All Events. Check this
        one. Then in the grid find the Error group. In this group, check the
        Exception and User Message events. If you are alone on the server, you
        can press Run now. If there is more activity, you will find need to
        set up a Column filter.

        All and all, I believe Profiler is quite easy to get started with. The
        GUI is fairly intuitive. It may be difficult to understand what all
        those events and columns are, but you don't have to understand all
        of them at once. There is a default selection of columns, and often
        this is sufficient.

        There are some buttons in the toolbar that permits you to stop and start
        a trace.



        --
        Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se

        Links for SQL Server Books Online:
        SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
        SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
        SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

        Comment

        • Chris Kennedy

          #5
          Re: UPDATE query gives Incorrect Syntax error

          On Aug 27, 7:08 am, Erland Sommarskog <esq...@sommars kog.sewrote:
          It's not that difficult. Start Profiler, select New Trace complete the
          Connection Dialog. In the dialog that comes up, click the Events Selection
          tab. Down to the right there is a check box, Show All Events. Check this
          one. Then in the grid find the Error group. In this group, check the
          Exception and User Message events. If you are alone on the server, you
          can press Run now. If there is more activity, you will find need to
          set up a Column filter.
          >
          All and all, I believe Profiler is quite easy to get started with. The
          GUI is fairly intuitive. It may be difficult to understand what all
          those events and columns are, but you don't have to understand all
          of them at once. There is a default selection of columns, and often
          this is sufficient.
          >
          There are some buttons in the toolbar that permits you to stop and start
          a trace.
          >
          --
          Erland Sommarskog, SQL Server MVP, esq...@sommarsk og.se
          >
          Links for SQL Server Books Online:
          SQL 2008:http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
          SQL 2005:http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
          SQL 2000:http://www.microsoft.com/sql/prodinf...ons/books.mspx
          I have just discovered that SQL Server 2005 Express Edition does not
          contain the Profiler tool. Any suggestions for an alternative or
          workaround?

          Chris

          Comment

          • Erland Sommarskog

            #6
            Re: UPDATE query gives Incorrect Syntax error

            Chris Kennedy (chrisk@clarke-energy.com) writes:
            I have just discovered that SQL Server 2005 Express Edition does not
            contain the Profiler tool. Any suggestions for an alternative or
            workaround?
            Sorry, I kind of vainly hoped that you would have a license of DevEdition
            around.

            You can still run a server-side trace, but that is admittedly a more
            difficult and is not as convenient for quick debugging.

            A license of Developer Edition is not that expensive, and getting access to
            Profiler may alone warrant the cost. You could also download and install
            Evaluation Edition.


            --
            Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se

            Books Online for SQL Server 2005 at

            Books Online for SQL Server 2000 at

            Comment

            Working...