This query is trying to run, but its return errors: Array ([0] = & gt; Array ([0] => 42000 [SQLSTATE] => 42000 [1] = & gt; 156 [code] => 156 [2] = & gt; [Microsoft] [SQL Server Native Client 11.0] [SQL Server] 'End' has the wrong syntax. [Messaging] => [Microsoft] [SQL Server Native Client 11.0] [SQL Server] The keyword 'end' is wrong with Syntax.)) SQL query: Select routines.date, routines.time, SUM (case when measurements.title = 'T_Luft_Temperatur' then CAST (REPLACE (routines.value, ',', '.') To decimal (18, 2)) and zero end ) Temperatur, SUM (case when measurements.title = 'T_Badende_per_Time' as cast (routines.value REPLACE (, ',', '.') As decimal (18, 2)) and zero Badende_Per_Time, SUM (The case is when measurements.title = 'T_Luft_Temperatur' as artists (in the form of routines.value REPLACE (, ',', '.') As decimal (18, 2)) and zero end ) As Luft_Temperat...