I have a function that returns a date string. I need this because I can't use a variable in a view, but I can use a function that returns a variable that I set ahead of time...
So I got all that working, but then I decided that if that I wanted it to return the current date if no date variable was set. I thought the code below wold work, but I get syntax errors...
DELIMITER $$
USE `cc`$$
DROP FUNCTION IF EXISTS `ox_date`$$
CREATE FUNCTION `ox_date`() RETURNS CHAR(50) CHARSET latin1
DECLARE ox VARCHAR(20)
IF @oxdate <1 THEN SET ox = CURDATE$$
ELSE SET ox = @oxdate$$
RETURN ox $$
DELIMITER ;
I tried isnull on that first if, but it wasn't any help.
cc$$ DROP FUNCTION IF EXISTSox_date$$ CREATE FUNCTIONox_date() RETURNS CHAR(50) CHARSET latin1 DECLARE ox VARCHAR(20)$$ IF @oxdate <1 THEN SET ox = CURDATE()$$ ELSE SET ox = @oxdate$$ END IF$$ RETURN ox $$ DELIMITER ; ............ (0 row(s) affected) Execution Time : 00:00:00:000 Transfer Time : 00:00:00:000 Total Time : 00:00:00:000 (0 row(s) affected, 1 warning(s)) Execution Time : 00:00:00:000 Transfer Time : 00:00:01:061 Total Time : 00:00:01:061 Error Code : 1064 You have an error in your SQL syntax; check