2

I am trying to use the SQLRowCount function after the select query. MSDN document says SQLRowCount doesn't work with the select query. So SQLRowCount is returning -1 to me.

But what is the alternate way if I want to retrieve the count of resultset returned by the select query?

For e.g.:

SQLCHAR* selectQuery = (SQLCHAR*)"SELECT * FROM table";
retCode = SQLExecDirectA(hStmt, selectQuery, SQL_NTS)
if (SQL_SUCCEEDED(retCode))
{
    SQLINTEGER numRows;
    retCode = SQLRowCount(hStmt, &numRows);
}

The above code is running perfectly with mysql but with sql server numRows is getting -1 as a value. What are the alternate ways I have to get the count of number of rows returned by the select query in this case?

Richard Hansen
  • 51,690
  • 20
  • 90
  • 97
  • 1
    not sure what you're trying to accomplish, but can't you do `SELECT COUNT(1) FROM table`? – Jason Jun 11 '13 at 14:46
  • Some DBMS let you do something like `select a, b, c, count(*) from table`, so that you won't have to query the same table twice. Don't know if that works with SQLServer though. - Edit: According to http://msdn.microsoft.com/de-de/library/ms175997.aspx this should work on SQLServer. – JimmyB Jun 11 '13 at 14:50
  • I am trying to execute the select query in c++ using the APIS. SQLRowCount function returns the number of rows affected my DML statements. – Mahesh Mahindrakar Jun 11 '13 at 18:19
  • 2
    This http://stackoverflow.com/questions/243782/need-a-row-count-after-select-statement-whats-the-optimal-sql-approach may help. – Ravi Singh Jun 12 '13 at 06:02

0 Answers0