Solved

mysql insert not working

Posted on 2012-04-08
5
378 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikipedia.org/wiki/PHP  Very powerful.  But a…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 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