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
Solved

mysql insert not working

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

Suggested Solutions

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
Introduction In this article, I will by showing a nice little trick for MySQL similar to that of my previous EE Article for SQLite (http://www.sqlite.org/), A SQLite Tidbit: Quick Numbers Table Generation (http://www.experts-exchange.com/A_3570.htm…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

839 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