This MAY actually be my first question. So, here 'goes.
"I swear this worked initially and doesn't work now." (take that for all it's worth.)
I have a table, as follows:
CREATE TABLE `meta_data` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`data_key` varchar(64) NOT NULL,
`data_value` varchar(64) NOT NULL,
PRIMARY KEY (`id`)
)
It has exactly one row, thus:
1,'current month','2014-05'
The idea is to create a function (a functional MySql object that returns a single value) that will retrieve the current month value. Easy peasy, right?
delimiter $$
create function f_current_run_date()
returns varchar(16)
BEGIN
declare current_run_date varchar(16);
SELECT data_value into @current_run_date from meta_data where data_key = 'current month' limit 1;
return current_run_date;
END$$
select 'current run date',f_current_run_date();$$
I swear to you that when I wrote this and executed this whole block, it worked fine. 10 minutes later, after an impromptu meeting, it returns null. When I extract the sql, (pulling out the 'into' clause) works exactly as I'd expect.
What gives? I'm beginning to feel like I'm insane here.
(This is MySql 5.1 btw.)