Faith Victory
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-db 2e8d41329a )
========================== ========== ========== ========== ========== ====
ALTER PROCEDURE [dbo].[PushNotificationBat chWrite]
(
@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].[PushNotificationBat ch] (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].[PushNotificationBat ch]
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].[PushNotificationBat ch]
SET [SentYN] = @SentYN
,[SentTimestamp] = @SentTimestamp
WHERE BatchID = @BatchID
END
END
(@BatchID 9cfb9462-6b85-495c-9b66-db
==========================
ALTER PROCEDURE [dbo].[PushNotificationBat
(
@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].[PushNotificationBat
SET NOCOUNT OFF;
END
ELSE
BEGIN
IF @MFUpdatedYN IS NOT NULL
BEGIN
--set the batch ID as updated on the mainframe
UPDATE [dbo].[PushNotificationBat
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].[PushNotificationBat
SET [SentYN] = @SentYN
,[SentTimestamp] = @SentTimestamp
WHERE BatchID = @BatchID
END
END
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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)
IF (@SentYN IS NULL) AND (@MFUpdatedYN IS NULL)
ASKER
Best solution!