0

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.

  • no way to do like above, but you can try a solution for PDO https://stackoverflow.com/questions/18511645/use-bound-parameter-multiple-times – V-K Oct 14 '20 at 15:26
  • Are you sure ? Will I have to pass one amount at a time ? It is not possible that the laravel has this limitation. – Gato de Schrödinger Oct 14 '20 at 16:49

0 Answers0