SP Not Inserting A New Row

I create this SP and I am expecting it to insert a new row but that is not happening.  What's the best way to handle this?

 (@BatchID         9cfb9462-6b85-495c-9b66-db2e8d41329a)


======================================================================

ALTER PROCEDURE [dbo].[PushNotificationBatchWrite]
      (
      @BatchID                          uniqueidentifier,
      @SentYN                        char(1) = null,
      @SentTimestamp            datetime = null,
      @MFUpdatedYN                    char(1) = null,
      @MFUpdatedTimestamp      datetime = null
      )
AS

IF (@SentYN = NULL) AND (@MFUpdatedYN = NULL)
      --insert the new batch ID row
      BEGIN
            SET NOCOUNT ON;

            INSERT INTO [dbo].[PushNotificationBatch] (BatchID) VALUES (@BatchID);

            SET NOCOUNT OFF;
      END
ELSE
      BEGIN
            IF @MFUpdatedYN IS NOT NULL
                  BEGIN
                        --set the batch ID as updated on the mainframe

                        UPDATE [dbo].[PushNotificationBatch]
                           SET [MFUpdatedYN] = @MFUpdatedYN
                                ,[MFUpdatedTimestamp] = @MFUpdatedTimestamp
                         WHERE BatchID = @BatchID
                        
                   END

            IF @SentYN IS NOT NULL
                  BEGIN
                        --set the batch ID as sent to the vendor
                        UPDATE [dbo].[PushNotificationBatch]
                           SET [SentYN] = @SentYN
                                ,[SentTimestamp] = @SentTimestamp
                         WHERE BatchID = @BatchID
                        
                   END
      END
faith victoryAsked:
Who is Participating?
 
Vaibhav GoelMSBI , SQL ConsultantCommented:
HELLO faith Victory

Please make an attempt to use changed code provided->

======================================================================

ALTER PROCEDURE [dbo].[PushNotificationBatchWrite]
      (
      @BatchID                          uniqueidentifier,
      @SentYN                        char(1) = null,
      @SentTimestamp            datetime = null,
      @MFUpdatedYN                    char(1) = null,
      @MFUpdatedTimestamp      datetime = null
      )
AS

IF (@SentYN IS NULL) AND (@MFUpdatedYN IS NULL)
     
      BEGIN
            SET NOCOUNT ON;

                        INSERT INTO [dbo].[PushNotificationBatch] (BatchID) VALUES (@BatchID);

            SET NOCOUNT OFF;
      END
ELSE
      BEGIN
            IF @MFUpdatedYN IS NOT NULL
                  BEGIN
                        --set the batch ID as updated on the mainframe

                        UPDATE [dbo].[PushNotificationBatch]
                           SET [MFUpdatedYN] = @MFUpdatedYN
                                ,[MFUpdatedTimestamp] = @MFUpdatedTimestamp
                         WHERE BatchID = @BatchID
                       
                   END

            IF @SentYN IS NOT NULL
                  BEGIN
                        --set the batch ID as sent to the vendor
                        UPDATE [dbo].[PushNotificationBatch]
                           SET [SentYN] = @SentYN
                                ,[SentTimestamp] = @SentTimestamp
                         WHERE BatchID = @BatchID
                       
                   END
      END


Vaibhav
1
 
Nakul VachhrajaniTechnical Architect, Capgemini IndiaCommented:
How do you call the stored procedure? What parameters are you passing from your calling code? It looks like @SentYN and @MFUpdatedTimestamp are not being passed as NULL.
0
 
Brian CroweDatabase AdministratorCommented:
No value ever equals NULL including NULL itself.  To check for NULL use the "IS" operator.

IF (@SentYN IS NULL) AND (@MFUpdatedYN IS NULL)
0
 
faith victoryAuthor Commented:
Best solution!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.