I want to get one value from a function using a case statement. I tried the following but it does not work:
CREATE FUNCTION [FATMS].[fnReturnByPeriod]
(
There are two types of CASE expression: simple and searched. You must choose one or the other - you can't use a mixture both types in one expression.
Try this:
SELECT CASE
WHEN @Period = 1 THEN 1
WHEN @Period > 1 AND @Period <= 7 THEN 2
WHEN @Period > 7 AND @Period <= 30 then 3
-- etc...
ELSE 0
END
Also, you need to assign the result to something as others have already pointed out.