Solved

mysql insert not working

Posted on 2012-04-08
5
382 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

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://…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

636 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