Click here to Skip to main content
15,913,129 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

SQL
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?

SQL
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.)
Posted
Comments
Sergey Alexandrovich Kryukov 26-Jun-14 14:55pm    
What, "I swear this worked initially and doesn't work now."?!
Then I swear you should stop working without Revision Control System, because you are not working, just wasting your time on something you can loose any time. :-)
—SA
Thava Rajan 27-Jun-14 1:35am    
it seems nothing wrong with your code check the data in the table whether the record is present or your data key is absolutely correct

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900