H
Hansjörg Zimmermann
Hi,
i try to implement a function which contains a CASE statement. Unfortunatly
i did only found samples with CASE statements within SQL-Statements.
The following code was rejected by the SQL-Server, and i have no idea what
the error is. Any ideas are welcome.
Thanks in advance.
--------------------------------------------------
CREATE FUNCTION [CalcFuelIMP] (@pVal integer, @pUnit tinyint, @pEngine
Char(1) )
RETURNS NUMERIC(12,5) AS
BEGIN
DECLARE @pResult Numeric(12,5)
SELECT CASE
WHEN (@pVal = 0 THEN SET @pResult = 0
WHEN @pUnit= 1 THEN SET @pResult = (@pVal)
WHEN @pUnit= 2 THEN SET @pResult = (@pVal / 4.543 * 3.7853)
WHEN @pUnit= 3 THEN SET @pResult = (@pVal * 4.543)
WHEN (@pEngine = 'J' or @pEngine = 'T') and @pUnit = 4 THEN SET @pResult =
(@pVal * 0.4535924 / 0.8 / 4.543)
WHEN (@pEngine = 'J' or @pEngine = 'T') and @pUnit = 5 THEN SET @pResult =
(@pVal / 0.8 / 3.7853)
WHEN (@pEngine = 'P' and @pUnit = 4 THEN SET @pResult = (@pVal * 0.4535924 /
0.719 / 4.543)
WHEN (@pEngine = 'P' and @pUnit = 5 THEN SET @pResult = (@pVal / 0.719 /
3.7853)
ELSE SET @pResult = -1
RETURN @pResult
END
GO
i try to implement a function which contains a CASE statement. Unfortunatly
i did only found samples with CASE statements within SQL-Statements.
The following code was rejected by the SQL-Server, and i have no idea what
the error is. Any ideas are welcome.
Thanks in advance.
--------------------------------------------------
CREATE FUNCTION [CalcFuelIMP] (@pVal integer, @pUnit tinyint, @pEngine
Char(1) )
RETURNS NUMERIC(12,5) AS
BEGIN
DECLARE @pResult Numeric(12,5)
SELECT CASE
WHEN (@pVal = 0 THEN SET @pResult = 0
WHEN @pUnit= 1 THEN SET @pResult = (@pVal)
WHEN @pUnit= 2 THEN SET @pResult = (@pVal / 4.543 * 3.7853)
WHEN @pUnit= 3 THEN SET @pResult = (@pVal * 4.543)
WHEN (@pEngine = 'J' or @pEngine = 'T') and @pUnit = 4 THEN SET @pResult =
(@pVal * 0.4535924 / 0.8 / 4.543)
WHEN (@pEngine = 'J' or @pEngine = 'T') and @pUnit = 5 THEN SET @pResult =
(@pVal / 0.8 / 3.7853)
WHEN (@pEngine = 'P' and @pUnit = 4 THEN SET @pResult = (@pVal * 0.4535924 /
0.719 / 4.543)
WHEN (@pEngine = 'P' and @pUnit = 5 THEN SET @pResult = (@pVal / 0.719 /
3.7853)
ELSE SET @pResult = -1
RETURN @pResult
END
GO