Solved

mysql insert not working

Posted on 2012-04-08
5
380 Views
Last Modified: 2012-04-08
The following procedure seems to be created properly, but when i call it, the while loop doesn't get executed.. I end up with a table with one row and a 0000-00-00 date.

call GetDatesInRange(2012-5-8, 2012-5-12)

DELIMITER //
 CREATE PROCEDURE GetDatesInRange(d1 date, d2 date)
     BEGIN
        declare sd date;
        declare ed date;

	set sd = d1;
        set ed = d2;


	create table allDates (	
		sd DATE not null,
		i INT(11),
		t VARCHAR(255)
		);
       while sd <= ed do
		insert into allDates (sd, i, t) values (sd, i, t);
		set sd = DATE_ADD(sd,INTERVAL 1 DAY);
	end while;
	
  END //
DELIMITER ;

Open in new window


Any help would be much appreciated.
Koza
0
Comment
Question by:Kyle Hamilton
  • 3
  • 2
5 Comments
 
LVL 17

Expert Comment

by:ramrom
ID: 37821241
the values clause refers to i and t. Where are these declared and given values?

What happens if you use

insert into allDates (sd) values (sd);
0
 
LVL 25

Author Comment

by:Kyle Hamilton
ID: 37821269
They were there for values I was going to define later. But it makes no difference. I took all references to them out and I still only get the one row with a 0000-00-00 date.
0
 
LVL 17

Accepted Solution

by:
ramrom earned 500 total points
ID: 37821314
I am not a MySQL expert - but I wonder abaout call GetDatesInRange(2012-5-8, 2012-5-12).
I suspect 2012-5-8 is being interpreted aa 2012 minus 5 minus 8.

try call GetDatesInRange("20120508", "201205012")
0
 
LVL 25

Author Comment

by:Kyle Hamilton
ID: 37821319
That almost worked.

 the mysql date format is 0000-00-00, so in the end this worked:

call GetDatesInRange("2012-05-08", "2012-05-12")

Thanks so much.
0
 
LVL 25

Author Closing Comment

by:Kyle Hamilton
ID: 37821322
Just a minor adjustment needed. see my last post.

Thanks so much!
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

680 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question