Sanjay Kumar

Sanjay Kumar

  • NA
  • 5k
  • 4.4m

CREATE PROCEDURE

Oct 14 2013 6:34 AM
If Row Exists, Update, Else Insert in Asp .net 

fields : StudentID, FirstName, LastName and Status
CREATE PROCEDURE ExistsUpdateInsert(
@StudentID int,
@FirstName [nvarchar](50),
@LastName [nvarchar](50),
@Status [nvarchar](50)
)
AS
BEGIN
IF EXISTS (SELECT StudentID FROM StudentTable WHERE StudentID =@StudentID)
  UPDATE StudentTable set StudentID=@StudentID WHERE Status='Active'
ELSE
  INSERT INTO StudentTable (StudentID, FirstName, LastName)
  VALUES (@StudentID, @FirstName, @LastName)
    END
END

please help code


Answers (5)