获取错误:无法将值NULL插入列' entryID'

时间:2016-03-28 14:13:32

标签: sql-server tsql stored-procedures

usp_auditRejectRequest:

CREATE PROCEDURE [a01].[usp_auditRejectRequest]
(@accountID UNIQUEIDENTIFIER , @GroupID UNIQUEIDENTIFIER)
AS
BEGIN
    INSERT INTO [a01].[tbl_enrollmentAudits]
        (entryID,entryDate, requestID, accountID, groupID, accepted, reason)
    VALUES( NULL,SYSDATETIMEOFFSET(), NULL, @accountID, @GroupID, 0, NULL);
END
GO

usp_auditAcceptRequest:

CREATE PROCEDURE [a01].[usp_auditAcceptRequest]
(@accountID UNIQUEIDENTIFIER , @GroupID UNIQUEIDENTIFIER)
AS
BEGIN
    INSERT INTO [a01].[tbl_enrollmentAudits]
        ( entryID,entryDate, requestID, accountID, groupID, accepted, reason)
    VALUES( NULL,SYSDATETIMEOFFSET(), NULL, @accountID, @GroupID, 1, NULL);
END
GO

usp_addRequest:

CREATE PROCEDURE [a01].[usp_addRequest]
(@AccountID UNIQUEIDENTIFIER, @GroupID UNIQUEIDENTIFIER)
AS
BEGIN
    SET NOCOUNT ON

    IF ([a01].[udf_isUserActive](@AccountID) = 0)
    BEGIN
        EXECUTE [a01].[usp_auditRejectRequest]
            @AccountID, @GroupID

        RETURN;
    END;

    IF ([a01].[udf_isUserBlockedFromGroup](@GroupID)=0)
    BEGIN
        EXECUTE [a01].[usp_auditRejectRequest]
             @AccountID, @GroupID

        RETURN;
    END;
END;
GO

输出:添加非活动用户:

    BEGIN
    DECLARE @AccountID UNIQUEIDENTIFIER;
    DECLARE @GroupID UNIQUEIDENTIFIER;


    (SELECT @AccountID = accountID 
    FROM [a01].[tbl_userAccounts] WHERE accountUsername='adrianab');

    (SELECT @GroupID = groupID FROM [a01].[tbl_groups] WHERE groupName LIKE '%Foo%');

    EXECUTE [a01].[usp_addRequest] @AccountID, @GroupID;
END;
GO

我无法宣布任何更多的独特IDENTIFIE,accountId和groupID是我可以按照讲师的指示使用的唯一ID。

1 个答案:

答案 0 :(得分:1)

   EXECUTE [a01].[usp_auditRejectRequest]
         NULL,NULL,NULL,@AccountID,@GroupID,0,'User not active'

当您仅定义2个参数时,您正在使用7个参数调用usp_auditRejectRequest过程。要么为你的程序添加更多的参数(你说你不能这样做),或者只是用2调用它并将“reason”值移到sproc:

    EXECUTE [a01].[usp_auditRejectRequest]
         @AccountID,@GroupID