我的逻辑一定有点古怪,因为当我测试以确保这些CASE
陈述是真实的时,我不会得到预期的结果......
例如,如果Sample1 = 'FI'
,Sample2 = 'GOVT'
并且Sample3 = 'GOVT'
,我不明白'OKFI'
......我知道我一定在某个地方有一些古怪的逻辑......
关于这些东西的最佳实践的任何想法?
CREATE FUNCTION SampleFunction
(
@Sample1 varchar(50),
@Sample2 varchar(50) = null,
@Sample3 varchar(50) = null
)
RETURNS VARCHAR(255)
AS
BEGIN
declare @output varchar(255)
SET @output =
CASE WHEN @Sample1 = 'CASH' THEN 'CASH'
WHEN @Sample1 = 'ST' THEN
CASE WHEN @Sample2 ='TBILL' THEN
CASE WHEN @Sample3 = 'TBILL' THEN 'OKFI'
WHEN @Sample1 = 'FI' THEN
CASE WHEN @Sample2 = 'GOVT' THEN
CASE WHEN @Sample3 = 'GOVT' THEN 'OKFI'
WHEN @Sample1 = 'DERV' THEN
CASE WHEN @Sample2 = 'CURRCONT' THEN
CASE WHEN @Sample3 = 'FORWARD' THEN 'CASH'
WHEN @Sample3 = 'SPOT' THEN 'CASH'
WHEN @Sample2 = 'SWAP' THEN
CASE WHEN @Sample3 = 'CURRSWAP' THEN 'CASH'
WHEN @Sample3 = 'INDXSWAP' THEN 'OTHER'
WHEN @Sample2 = 'FUTURE' THEN
CASE WHEN @Sample3 = 'COMFUT' THEN 'COM'
WHEN @Sample3 = 'BFUT' THEN 'OKFI'
WHEN @Sample3 = 'NDXFUT' THEN 'OKSHARES'
WHEN @Sample3 = 'EQFUT' THEN 'OKSHARES'
WHEN @Sample3 = 'CURRFUT' THEN 'CASH'
WHEN @Sample2 = 'OPTION' THEN
CASE WHEN @Sample3 = 'CUROPTION' THEN 'CASH' END
ELSE 'OTHER'
END END END
END END END
END END END RETURN @Output
END -- FUNCTION