Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2011
    Posts
    2

    Question Unanswered: Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT' or 'UPDATE'

    Hello, I'm trying to work with a access database and have found that, if possible, if exists sql structure would be easier then implementing the same logic in vbscript with many unique SQL statements (one statement vs many). However, when I try to do the "IF EXISTS (SELECT...) UPDATE ... ELSE INSERT INTO ..." construct access gives the error in the title and highlights the IF part of the statement. How does access expect this construct to be formatted? Thanks.

    P.S. I'm using Access 2007 with a access 2002 compatible db for use with asp

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    IF EXISTS is not valid in Access, the Jet Engine does not recognise it. You can use COUNT(*) (in SQL) or the DCount() function (in VBA). Also notice that you cannot create conditional structures (IF ... ELSE) in an Access Query, the only exception being the IIf() function.
    Have a nice day!

  3. #3
    Join Date
    Jun 2011
    Posts
    2
    Thanks. I ended up solving the problem by using a SELECT recordset and checking for EOF to determine if the field was present or not.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •