SQL Custom Commands
Posted: Mon 08 May 2023 2:47 pm
I've been in conversation with freddie about this.
I have a table with grass temp/soil temps/ponds temps/soil moisture which is being populated every 1 minute with a 96 hour retension.
freddie provided me with a little SQL to extract the daily mins/maxes & times, and then put that in to another table. The command runs at the CMX rollover time. The problem is, Only LogDate is correctly being added. The mins/maxes are all 0.0 and there's no times of those mins/maxes.
If I take the SQL command, and replace the <#metdateyesterday> with the actual date - in this case, 05/07/2023 - then run the command manually in SQL, it correctly populates the columns with the data and times.
This just adds 0.0 to the data fields and leaves the date/times blank when using CMX. Debug shows no errors.
Changing the webtags to manual dates and running it in SQL works fine.
Obviously, I am doing something wrong, but I don't know what it is. 
I have a table with grass temp/soil temps/ponds temps/soil moisture which is being populated every 1 minute with a 96 hour retension.
freddie provided me with a little SQL to extract the daily mins/maxes & times, and then put that in to another table. The command runs at the CMX rollover time. The problem is, Only LogDate is correctly being added. The mins/maxes are all 0.0 and there's no times of those mins/maxes.
If I take the SQL command, and replace the <#metdateyesterday> with the actual date - in this case, 05/07/2023 - then run the command manually in SQL, it correctly populates the columns with the data and times.
This just adds 0.0 to the data fields and leaves the date/times blank when using CMX. Debug shows no errors.
Code: Select all
INSERT IGNORE INTO ExtraDayfile (LogDate,GrassMin,GrassTMin)
Values(
('<#metdateyesterday format=yyyy-MM-dd>'),
(select min(GrassTemp) from Soil where LogDateTime >= str_to_date('<#metdateyesterday> 00:00:00', '%m/%d/%Y %H:%i:%s') and LogDateTime < str_to_date('<#metdateyesterday> 23:59:59', '%Y-%m-%d %H:%i:%s')),
(select min(LogDateTime) from Soil where GrassTemp = (select min(GrassTemp) from Soil where LogDateTime >= str_to_date('<#metdateyesterday> 00:00:00', '%m/%d/%Y %H:%i:%s') and LogDateTime < str_to_date('<#metdateyesterday> 23:59:59', '%Y-%m-%d %H:%i:%s')) and LogDateTime >= str_to_date('<#metdateyesterday> 00:00:00', '%m/%d/%Y %H:%i:%s') and LogDateTime < str_to_date('<#metdateyesterday> 23:59:59', '%Y-%m-%d %H:%i:%s')));Code: Select all
INSERT IGNORE INTO ExtraDayfile (LogDate,GrassMin,GrassTMin)
Values(
('2023/05/07'),
(select min(GrassTemp) from Soil where LogDateTime >= str_to_date('05/07/2023 00:00:00', '%m/%d/%Y %H:%i:%s') and LogDateTime < str_to_date('23-05-07 23:59:59', '%Y-%m-%d %H:%i:%s')),
(select min(LogDateTime) from Soil where GrassTemp = (select min(GrassTemp) from Soil where LogDateTime >= str_to_date('05/07/2023 00:00:00', '%m/%d/%Y %H:%i:%s') and LogDateTime < str_to_date('23-05-07 23:59:59', '%Y-%m-%d %H:%i:%s')) and LogDateTime >= str_to_date('05/07/2023 00:00:00', '%m/%d/%Y %H:%i:%s') and LogDateTime < str_to_date('23-05-07 23:59:59', '%Y-%m-%d %H:%i:%s')));