I have a fairly large, complex chunk of SQL that creates a report for a particular page. This SQL has several variable declarations at the top, which I suspect is giving me problems.
When I get the ODBC result, I have to use odbc_next_result()
to get past the empty result sets that seem to be returned with the variables. That seems to be no problem. When I finally get to the "real" result, odbc_num_rows()
tells me it has over 12 thousand rows, when in actuality it has 6.
Here is an example of what I'm doing, to give you an idea, without going into details on the class definitions:
$report = $db->execute(Reports::create_sql('sales-report-full'));
while(odbc_num_rows($report) <= 1) {
odbc_next_result($report);
}
echo odbc_num_rows($report);
The SQL looks something like this:
DECLARE @actualYear int = YEAR(GETDATE());
DECLARE @curYear int = YEAR(GETDATE());
IF MONTH(GETDATE()) = 1
SELECT @curYear = @curYear - 1;
DECLARE @lastYear int = @curYear-1;
DECLARE @actualLastYear int = @actualYear-1;
DECLARE @tomorrow datetime = DATEADD(dd, 1, GETDATE());
SELECT * FROM really_big_query