I'm running an application on top of MySQL in which I store part of a sql query in table. The application then takes this string adds an identifier and executes it. For example, in the database a sample string stored would be "select max(obs_datetime) from obs where patient_id=" and the application places the identifier at the end of that string and executes it to get the date, and then sends an SMS if that date matches the one set by the user.
I'm now trying to build a query that will check to make sure that the SMS got sent when it should have so I'm trying to create a sql query where I can get the date that is executed by the application i.e. get the string stored in the database concatenate it to the patient_id to get the date, and then use that date within a timediff.
I've looked at dynamic SQL How To have Dynamic SQL in MySQL Stored Procedure and stored procedures, but can't figure out how to do it.
Thanks,
Here I'm posting a bit more information. The table data for table SMS looks like this
id | name | sql_query
1 | welcome | select max(obs_datetime) from encounter where patient_id =
and what I would like to do is create a query that says
select name from SMS s, patient p where datediff(now(),sql_query_date) = 1;
where sql_query_date select the text from the SMS table and concatenates it with p.patient_id to create a query like select max(obs_datetime) from encounter where patient_id = p.patient_id
Hope I explained myself better this time.