Results 1 to 2 of 2

Thread: iif and odbc

  1. #1
    Join Date
    Jan 2004

    Unanswered: iif and odbc

    Hello all,

    I have an issue with the IIF command when used with masaccess-odbc driver. The following command works beautifully within access.

    SELECT iif(FK_PROTOCOL_ID = 5, "Proto5_ver_dHCV",0) AS proto5, FROM RUN;

    If the run.protocol_id column has the number 5 in it, the string Proto5_ver_dHCV is placed into proto5 if not a 0 is placed in proto5.

    However, when I run the same command from within an excel spreadsheet, I get the error message too few parameters expected 1.

    Is there anyway for that that SQL statement or similar to be executed through the ODBC driver?

    Any comments are appreciated!


  2. #2
    Join Date
    Apr 2013



    Your post is pretty old, but today I faced the same problem: I needed to invoke a query with a IIF inside via ODBC (Java).
    As you point out, the ODBC driver does not understand IIF, so it returns an error: "Too few parameters. Expected 1."
    This is a pretty misleading error message, because if you remove the IIF part of the query, no parameters inside of it, the query works.

    I have found a nice workaround, though:
    We open Access, create a new query (via menus), we open its SQL view, we paste our query there (the one that has the IIF), we run it to see it works as we need, then we close it, so that Access ask us if we want to save it: We enter a name for this query. Easy. Well, now this named query can be used from ODBC clients as if it was an SQLServer stored procedure!

    For instance, in Java, we could call it like this:

    CallableStatement st = con.prepareCall("{call summa(?, ?)}");
    st.setString(1, "135099");
    st.setString(2, "dummy");
    ResultSet r = st.executeQuery();
    if ( {
    Although it need an extra "dummy" parameter, I don't know why, but it does.

    I hope this hint helps!

Posting Permissions

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