0

我收到一个错误

= 附近的语法不正确

执行此过程时:

DECLARE @I_BRANCH_ID VARCHAR(MAX) 

EXEC GETBALANCE CASE WHEN @I_BRANCH_ID ='' THEN 0 ELSE @I_BRANCH_ID END
4

3 回答 3

1

您不能将条件语法放入这样的 EXECUTE 语句中。

相反,请尝试:

IF (@I_BRANCH_ID = '')
    SET @I_BRANCH_ID = '0'

EXECUTE GetBalance @I_BRANCH_ID

编辑:

使用更多参数,您可以简化为:

SELECT @param1 = CASE WHEN @param1 = '' THEN '0' ELSE @param1 END,
       @param2 = CASE WHEN @param2 = '' THEN '0' ELSE @param2 END,
       @param3 = CASE WHEN @param3 = '' THEN '0' ELSE @param3 END
       ... etc etc
于 2012-12-05T09:40:17.497 回答
0

尝试将变量的值与 EXECUTE 语句分开设置:

DECLARE @I_BRANCH_ID VARCHAR(MAX) 

SET @I_BRANCH_ID = CASE WHEN @I_BRANCH_ID = '' THEN 0 ELSE @I_BRANCH_ID END

EXEC GETBALANCE @I_BRANCH_ID
于 2012-12-05T09:45:51.667 回答
0
DECLARE @I_BRANCH_ID VARCHAR(MAX)
SET @I_BRANCH_ID = CASE WHEN @I_BRANCH_ID = '' THEN '0' ELSE @I_BRANCH_ID END
EXEC GETBALANCE @I_BRANCH_ID
于 2012-12-05T09:46:22.177 回答