I am attempting to sum a field from a MS SQL table:-
$BudgetedHours = array();
foreach($WorkPackCharVarList as $ThisSubJob)
{
echo "<p>$ThisSubJob</p>";
$sql="
SELECT SUM(Quantity)
AS BudgetHours
FROM [Workbench].[dbo].[EstimateLines]
WHERE $ThisSubJob = [EstimateLines].[JobCode]";
$stmt = sqlsrv_query( $conn, $sql);
if( $stmt === false)
{
die( print_r( sqlsrv_errors(), true) );
}
$row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC);
$BudgetedHours[] = $row[BudgetHours];
echo "<p>BudgetHours = $row[BudgetHours]</p>";
sqlsrv_free_stmt( $stmt);
This gives a SQL error:-
Array ( [0] => Array ( [0] => 22003 [SQLSTATE] => 22003 [1] => 248 [code] => 248 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]The conversion of the varchar value ‘01910002003001’ overflowed an int column. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]The conversion of the varchar value ‘01910002003001’ overflowed an int column. ) )
The array $WorkPackCharVarList has been filled using a strval() of some integers, all shorter than 20 characters.
The field EstimateLines.JobCode is varchar(20)
The SQL query works fine when pasted into MSSQL. with $ThisSubJob replaced by ‘01910002003001’ .