如果Else不在TSQL中工作

时间:2015-05-28 05:44:46

标签: sql sql-server stored-procedures sql-server-2012

如果永远不会奏效。总是陷入其他条件。我已调试并检查@nextapprover不为空。

IF (@nextApprover != NULL)
BEGIN
    UPDATE CallWatching
    SET EmployeeNo = @employeeNo
    WHERE @SRFID = MasterCode;

    INSERT INTO CallForwarding (
        MasterCode
        ,EmployeeNo
        ,ApproverNo
        ,IsForwarded
        ,ForwardBy
        )
    VALUES (
        @SRFID
        ,@EmployeeNo
        ,@nextApprover
        ,0
        ,@EmployeeNo
        )
END
ELSE
BEGIN
    UPDATE CallWatching
    SET STATUS = 1
    WHERE @SRFID = MasterCode;
END

1 个答案:

答案 0 :(得分:5)

使用IS NOT NULL

即。变更:if(@nextApprover!=null)IF(@nextApprover IS NOT NULL)

此外,您应该<>而不是!=,因为它符合ANSI标准