Hello.
I need to create a sensor retrieving data from a MySQL database, but the table name is dynmaic. So i have to use a Prepared Statement to produce the query string first As in:
SET @c = '131'; SET @tb = CONCAT('hist_',YEAR(CURDATE()), LPAD(MONTH(CURDATE()),2,0)); SET @s = CONCAT('select truncate(sum(stime)/60,0) as min from ', @tb, ' where c_id=',@c,' and `time` > CURDATE()'); PREPARE stmt1 FROM @s; EXECUTE stmt1; DEALLOCATE PREPARE stmt1;
But I only get "Fatal Error encountered during command execution". I tried thru the gui from SQL_V2.exe, same result.
Can someone point me to the right direction i should take to make this work? Thank you very much.
Add comment