Sowmya Sirsi

Sowmya Sirsi

  • 2k
  • 131
  • 4.7k

Passing empty parameter in sp

Oct 12 2021 6:57 AM

Hi Team,

I have written the below query  to insert the records into table.

I have applied IS NULL condition if @IMSI param is not passing should be updated as NULL, rest all parm data should be inserted. Unfortunately the highlighted query itself is not working properly.

Can anyone suggest me regarding this

ALTER PROCEDURE [dbo].[sp_InsertIntoFavoriteAccount]
@AccountName varchar(200),
@AccountNumber varchar(200),
@BankName varchar(200),
@CustomerMSISDN varchar(20),
@OperationType varchar(10)='Add',
@IMSI varchar(500)=NULL,

AS
BEGIN
    BEGIN TRY    
        IF(@IMSI IS NOT NULL)
            BEGIN 
                INSERT INTO [dbo].[FavoriteAccountDetails] ([BANKNAME],[MSISDN],[IMSI],[ACCOUNTNUMBER],[ACCOUNTNAME],  [OPERATIONTYPE],[LATESTUPDATEDDATE],[REQUESTEDDATE],[UPDATEDDATE])
                VALUES(@BankName,@CustomerMSISDN,@IMSI,@AccountNumber,@AccountName,@OperationType,GETDATE(),GETDATE(),GETDATE())
                SELECT 1 AS rowAffected;
            END
ELSE IF((@IMSI IS NULL) or (@IMSI = ' '))
          BEGIN
              INSERT INTO [dbo].[FavoriteAccountDetails] ([BANKNAME],[MSISDN],[IMSI],[ACCOUNTNUMBER],[ACCOUNTNAME],          [OPERATIONTYPE],[LATESTUPDATEDDATE],[REQUESTEDDATE],[UPDATEDDATE])
              VALUES(@BankName,@CustomerMSISDN,@IMSI,@AccountNumber,@AccountName,@OperationType,GETDATE(),GETDATE(),GETDATE())
                SELECT 1 AS rowAffected;
   END
 
   END TRY
END


Answers (3)