I have a querie that receives the: year several times. This year is the same value. How would I go about passing this value via bind? As below the error.
$year = 2020;
$result = DB::select("
SELECT
SUM(CASE WHEN demission IS NULL AND MONTH(admission) = 1 AND YEAR(admission) = :year THEN 1 ELSE 0 END) adm1,
SUM(CASE WHEN demission IS NULL AND MONTH(admission) = 2 AND YEAR(admission) = :year THEN 1 ELSE 0 END) adm2,
SUM(CASE WHEN demission IS NULL AND MONTH(admission) = 3 AND YEAR(admission) = :year THEN 1 ELSE 0 END) adm3,
SUM(CASE WHEN demission IS NULL AND MONTH(admission) = 4 AND YEAR(admission) = :year THEN 1 ELSE 0 END) adm4,
SUM(CASE WHEN demission IS NULL AND MONTH(admission) = 5 AND YEAR(admission) = :year THEN 1 ELSE 0 END) adm5,
SUM(CASE WHEN demission IS NULL AND MONTH(admission) = 6 AND YEAR(admission) = :year THEN 1 ELSE 0 END) adm6,
SUM(CASE WHEN demission IS NULL AND YEAR(admission) = :year THEN 1 ELSE 0 END) adm_total,
WHERE client_id = :client_id;", array('client_id'=>$clientId, 'year'=>$year));
This way below works (with single occurrence of the year)
$year = 2020;
$result = DB::select("
SELECT
SUM(CASE WHEN YEAR(demission) = :year THEN 1 ELSE 0 END) dem_total
WHERE client_id = :client_id;", array('client_id'=>$clientId, 'year'=>$year));
The stackoverflow-pt doesn't have a lot of laravel content.