I am trying to migrate a scalar valued function of MS SQL to function in MySQL and have been using the following syntax as Queries to create function named xx4.
DROP FUNCTION IF EXISTS `xx4`;`
CREATE DEFINER = CURRENT_USER FUNCTION `xx4`(code VARCHAR(3))`
RETURNS CHAR`
BEGIN
`DECLARE coden INT UNSIGNED DEFAULT 0= CAST(CODE AS UNSIGNED)`
`DECLARE ret CHAR =CASE`
`when coden<50 then 'A'`
`when coden<100 then 'B'`
`when coden<350 then 'C'`
`when coden<360 then 'D'`
`else null`
`END`
`RETURN ret`
`END;
It gives me error as:
at Declare ret char=Case when coden<50 then 'A' when coden<100 w' at line 4
Can you please tell me where I am wrong? Appreciate your help.
default 0=? what's that supposed to be? trying to setcodento be the boolean result of0=cast(...)? default values can't be expressions.