Solved

mysql insert not working

Posted on 2012-04-08
5
375 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Just a minor adjustment needed. see my last post.

Thanks so much!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now