ALTER FUNCTION WEEKDAYS(@DAY VARCHAR)
RETURNS INT
AS BEGIN
IF(@DAY IS NULL)
RETURN 0
DECLARE @OUTPUT INT
SELECT @OUTPUT=
CASE WHEN SUBSTRING(@DAY,1,1) = 'M' THEN 1
WHEN SUBSTRING(@DAY,1,2) = 'TU' THEN 2
WHEN SUBSTRING(@DAY,1,1) = 'W' THEN 3
WHEN SUBSTRING(@DAY,1,2) = 'TH' THEN 4
WHEN SUBSTRING(@DAY,1,1) = 'F' THEN 5
WHEN SUBSTRING(@DAY,1,2) = 'SA' THEN 6
WHEN SUBSTRING(@DAY,1,2) = 'SU' THEN 7
ELSE
99 END
RETURN @OUTPUT
END
I have this function with me. In case of monday, wednesday and friday the output that the function is printing is correct. but in other cases it is printing the output from else condition.