Ramco Ramco

Ramco Ramco

  • 439
  • 3.4k
  • 544.4k

Wrong Value Returned

Aug 20 2024 9:06 AM

Hi

 I have below code . It returns success = false though record is inserted.When i comment below 2 lines then it works o.k

IF @@ROWCOUNT = 0
       SET @Success = 0

ALTER PROCEDURE [dbo].[sp_Department]
       @Action VARCHAR(1)
	  ,@DocEntryNo int = Null
      ,@Description VARCHAR(50) = NULL
	  ,@ShortName VARCHAR(15) = NULL
	  ,@Status bit = NULL
	  ,@Success BIT OUTPUT
AS
BEGIN
      SET NOCOUNT ON;
 
      --INSERT
      IF @Action = 'I'
      BEGIN
        INSERT INTO dbo.Department(Description,ShortName,status,createdby,createdon,updatedby,updatedon)
        VALUES (@Description,@ShortName,1,1,GETDATE(),1,GETDATE())
		SET @Success = 1
      END
 
 
      --DELETE
      IF @Action = 'D'
      BEGIN
        UPDATE dbo.Department
        SET status = 0 , updatedon = GETDATE(),updatedby = 1 WHERE docentry = @DocEntryNo
		SET @Success = 1
      END

	  IF @@ROWCOUNT = 0
       SET @Success = 0
END

Thanks


Answers (3)