How to get COUNT(*) working?

Nov 2, 2011 at 2:48 PM


Just downloaded the library to connect my Excel project with SQLLite. I'm a newbie with SQL, but need the number of records from a table to dimension an array. If I use "SQLite3PrepareV2(myDbHandle, "SELECT COUNT(*) FROM Project", myStmtHandle)" my return value is "1". How can I put the result of "COUNT" in a variable?

Thanks in Advance,


Nov 2, 2011 at 3:16 PM

Hi Henk,

After doing the query you'd use SQLite3ColumnInt32(stmtHandle, 0) to retrieve the value of the first column in the results - in this case the Count.


Nov 2, 2011 at 3:17 PM

Thank you, for your fast response!

Nov 2, 2011 at 3:35 PM


Every table I use gives a result of 0!

    RetVal = SQLite3PrepareV2(myDbHandle, "SELECT COUNT(*) FROM project", myStmtHandle)
    Debug.Print "SQLite3PrepareV2 returned " & RetVal     (Result 0)
    iNumRecords = SQLite3ColumnInt32(myStmtHandle, 0)
    Debug.Print "SQLite3ColumnInt32 returned " & iNumRecords    (Result 0, must be 7)

Do you have a hint?

Nov 2, 2011 at 3:38 PM

Hi Henk,

After prepare, you need to call SQLite3Step to actually execute the query and place you on the first result row - see the documentation here: