0

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.

Community
  • 1
  • 1
jblaya
  • 5
  • 2
  • Can you explain what "the SMS got sent when it should have to" ? Can you post more explanation? – Mikaël Mayer Jun 28 '13 at 22:55
  • What is your question, please? – RandomSeed Jun 28 '13 at 23:24
  • Just edited to hopefully make it more understandable. As far as "the SMS got sent when it should have" is the objective of the query e.g. be able to create a query that looks at the SMS table and finds the SMSs that should have been sent today. – jblaya Jun 29 '13 at 15:45
  • I still haven't found anyone that can respond this, if anyone has an idea. – jblaya Jul 04 '13 at 16:03

0 Answers0