Checking for Nulls ina SP

  • I have the following SP:

    CREATE PROCEDURE dbo.GenericWorkFlowSequence_Insert_One

    (

    @nvcGWFSName nvarchar(50),

    @intGWFID int,

    @nvcRoleID nvarchar(256),

    @nvcASCU nvarchar(256)

    )

    AS

    SET NOCOUNT OFF;

    DECLARE @intGWFSSeqNbr int

    SET @intGWFSSeqNbr= (select max(intGWFSSeqNbr)+100 from tblGenericWorkFlowSequence where intGWFID = @intGWFID group by intGWFID)

    IF @intGWFSSeqNbr = NULL

    BEGIN

    SET @intGWFSSeqNbr = 0

    END

    INSERT INTO

    tblGenericWorkFlowSequence

    (

    nvcGWFSName,

    intGWFSSeqnbr,

    intGWFID,

    nvcRoleID,

    dtASCD,

    nvcASCU

    )

    VALUES

    (

    @nvcGWFSName,

    @intGWFSSeqNbr,

    @intGWFID,

    @nvcRoleID,

    getdate(),

    @nvcASCU

    )

    GO

    As you can see, I am setting the value to 0 if it is null but when I check the value, it still has nulls.

  • Very Simple Just change the Statement from

     

    IF @intGWFSSeqNbr = NULL

    To 

    IF @intGWFSSeqNbr IS  NULL

    This will work for you.

    Do let me know if you have any further queries


    Kindest Regards,

    Sureshkumar Ramakrishnan

  • Worked like a charm. Thanks.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply