在自定义函数中声明多个变量



我正在尝试创建一个函数。该函数将接收两个参数,我希望它返回一个字符串。

例如

Paramter 1          Parameter 2
@CurrName           @Currency
SEP17 3600 CALL     GBP
AUG17 4000 CALL     EUR

所以我的函数将采用两个参数,请注意参数 1 @CurrName将始终是 3 个字母(月份(和 2 位我们不关心的数字。

所以我希望如果@FX是英镑,则字符串的开头返回为"UKX",如果是欧元,则为"SXE5">

我想要的输出是这样的

1st one ->      UKX 9 3600
2nd one -)      SXE5 8 4000

但是,我在第一位上遇到了麻烦,因为它似乎不喜欢我声明变量@tickStart"函数中包含的选择语句无法将数据返回给客户端"的事实。

CREATE FUNCTION ufOptionName 
(
-- Add the parameters for the function here
@CurrName nvarchar(30),
@FX nvarchar(3)
)
RETURNS nvarchar(30)
AS
BEGIN
-- Declare the return variable here
DECLARE @newName nvarchar(30),
@tickStart nvarchar(10)
select case     
when @FX = 'EUR' then set @tickStart = 'SX5E'
when @FX = 'GBP' then set @tickStart = 'UKX'
else set @tickStart = 'US'
end
-- Return the result of the function
RETURN @newName
END
GO

使用这个:

SET @tickStart = case     
when @FX = 'EUR' then 'SX5E'
when @FX = 'GBP' then 'UKX'
else 'US'
end

最新更新