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]
(
In what way does it "not work"? Does it produce an error when you try to execute it? Does it return an unexpected result?
Off the top of my head, there are several problems:
Your case statement returns 1
in all cases.
The case statement is also combining two different types of CASE
semantics:
CASE @Period
WHEN THEN
WHEN THEN
ELSE
END
or
CASE
WHEN @Period = THEN
WHEN @Period = THEN
ELSE
END
The second form allows you to use unrelated conditions, whereas the first can only check for different values of @Period
.
Further, you're returning the value of @Period, not the value generated by the CASE statement.