1

I want to populate my table "MyDates" with a range of dates as shown in the code below. When I run the code I get this error "Unknown system variable 'dateStart'"

DECLARE
     dateStart  DATE   DEFAULT '2011-01-01';
DECLARE
     dateEnd DATE   DEFAULT'2011-12-31';
WHILE dateStart<=dateEnd DO
INSERT
     INTO
          MyDates
          (
               mydate
          )
          VALUES
          (
               dateStart
          ) ;
SET dateStart=date_add(dateStart,INTERVAL 1 DAY) ;
END WHILE;
END;
Jeremy Hunts
  • 353
  • 1
  • 5
  • 14
  • Try adding the code inside a mysql function, then call the function. – Lamar Oct 12 '17 at 10:52
  • There is nothing wrong in the procedure body. It should work. Also show your SP signature. – Ravinder Reddy Oct 12 '17 at 12:51
  • I think it is you attempting to include defaults that is the problem. see https://stackoverflow.com/questions/10132024/how-to-populate-a-table-with-a-range-of-dates which appears to be the source of your code, but it does not have default values. *Not sure if MySQL allows this yet.* also see http://rextester.com/CSLKE1780 – Paul Maxwell Oct 15 '17 at 03:37

0 Answers0