CREATE PROCEDURE [dbo].[SaveOrUpdateStudent]
@StudentId int = 0
,@Name varchar(50) = ''
,@Age int = 0
AS
BEGIN
BEGIN TRAN
IF(@StudentId = 0)
BEGIN
INSERT INTO Students([Name], Age) VALUES (@Name,@Age)
SET @StudentId = (SELECT SCOPE_IDENTITY())
END
ELSE
BEGIN
UPDATE Students SET [Name]=@Name, Age=@Age WHERE StudentId=@StudentId
END
SELECT * FROM Students WHERE StudentId=@StudentId
COMMIT TRAN
END
0 Comments