Sql 在自定义函数中声明多个变量
我正在尝试创建一个函数。该函数将接收两个参数&我希望它返回一个字符串 比如说Sql 在自定义函数中声明多个变量,sql,sql-server,Sql,Sql Server,我正在尝试创建一个函数。该函数将接收两个参数&我希望它返回一个字符串 比如说 Paramter 1 Parameter 2 @CurrName @Currency SEP17 3600 CALL GBP AUG17 4000 CALL EUR 因此,我的函数将采用两个参数,请注意参数1@CurrName始终是3个字母和2个数字,我们不关心 因此,我希望如果@FX是GBP,字符串的开头返回UKX,如果是EUR
Paramter 1 Parameter 2
@CurrName @Currency
SEP17 3600 CALL GBP
AUG17 4000 CALL EUR
因此,我的函数将采用两个参数,请注意参数1@CurrName始终是3个字母和2个数字,我们不关心
因此,我希望如果@FX是GBP,字符串的开头返回UKX,如果是EUR,则返回SXE5
我希望从中得到的输出是这样的
1st one -> UKX 9 3600
2nd one -) SXE5 8 4000
但是,我在第一位遇到了问题,因为它似乎不喜欢我声明了变量@tickStart,函数中包含的select语句无法将数据返回给客户机
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