Creating Days in a Year - Stored Procedure

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I found this code below online and I am trying to modify it for my needs. I want to pass a YEAR (Int) to the stored procedure and have it create all the day in that passed year. With one tweak, If the day is Sunday the "sStatus" field will equal "Closed" ELSE "Open". All attempts come up with ERRORS. Also, I would like the sdate field to be a DATE result. Little help please? I appreciate it.

USE colombo;

-- this table will store dates sequence CREATE TABLE seq_dates
(
   sdate DATETIME NOT NULL,
   sStatus VARCHAR NULL,
);

DROP PROCEDURE IF EXISTS colombo.sp_init_dates;

CREATE PROCEDURE colombo.sp_init_dates
(IN p_fdate DATETIME, IN p_tdate DATETIME)
BEGIN
DECLARE v_thedate DATETIME;
DECLARE v_Status VARCHAR;

TRUNCATE TABLE colombo.seq_dates;

SET v_thedate = p_fdate;

WHILE (v_thedate < p_tdate) DO

IF (DayName(v_theDate) = "Sunday" {
SET v_Status = "Closed";
}else{
SET v_Status = "Open";
}  // I know this CODE is wrong

   -- insert dates squence into seq_dates table
   INSERT INTO seq_dates (sdate, sStatus)
   VALUES (v_thedate, v_Status);

   -- go to the next day
   SET v_thedate = DATE_ADD(v_thedate, INTERVAL 1 DAY);

END WHILE;

END;

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux