Link to home
Start Free TrialLog in
Avatar of Faith Victory
Faith VictoryFlag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Vaibhav Goel
Vaibhav Goel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nakul Vachhrajani
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.
No value ever equals NULL including NULL itself.  To check for NULL use the "IS" operator.

IF (@SentYN IS NULL) AND (@MFUpdatedYN IS NULL)
Avatar of Faith Victory

ASKER

Best solution!