- Code: Select all
$query = "SELECT EXPDATE,SUM(ORDTOTAL) ";
$query .= "FROM OEORDH ";
$query .= "WHERE TYPE='1' AND ORDTOTAL>'0' ";
$query .= "GROUP BY MONTH(EXPDATE)";
$result = mssql_query($query);
echo "<table border=\"1\"><tr align=\"center\"><td><b>Ship Date</b></td><td><b>$ Amount</b></td></tr>";
while($row = mssql_fetch_array($result))
{
echo "<tr align=\"center\"><td>";
echo date("Y/m/d", strtotime($row["EXPDATE"]));
echo "</td><td>$" . number_format($row["ORDTOTAL"],2) . "</td></tr>";
}
Unfortunately, I keep getting this error:
Warning: mssql_query() [function.mssql-query]: message: Column 'OEORDH.EXPDATE' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. (severity 16) in C:\www\toship\index2.php on line 30
Warning: mssql_query() [function.mssql-query]: Query failed in C:\www\toship\index2.php on line 30
Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-result resource in C:\www\toship\index2.php on line 34
I used this code, without the SUM and GROUP BY functions, and it pulls the data properly. However, I get a bunch of duplicate entries for each day, and hundreds per month. That's why I would like to group them all by month. Does anyone see any ideas as to why this is not working?
Windows7-64, Apache (2.2.22), MSSQL (2008 R2), PHP (5.2.17)


