ALTER PROCEDURE [dbo].[SP_Teacher]
@TeacherId varchar(50)
,@FullName varchar(MAX)
,@SubjectName varchar(6)

AS
BEGIN TRAN
IF(@TeacherId = 0) --Insert
BEGIN
SET @TeacherId = (SELECT MAX(TeacherId) FROM Teacher) + 1

INSERT INTO Teacher  (TeacherId, FullName, SubjectName)
           VALUES(@TeacherId, @FullName, @SubjectName)

SELECT * FROM Teacher WHERE TeacherId=@TeacherId

END
ELSE IF(@TeacherId > 0) --Update
BEGIN
IF (@TeacherId = 0)
BEGIN
RollBACK
RAISERROR (N'Invalid Teacher !!!~',16,1);
RETURN
END

UPDATE Teacher SET FullName=@FullName
   ,SubjectName=@SubjectName
WHERE TeacherId=@TeacherId

SELECT * FROM Teacher WHERE TeacherId=@TeacherId
END
COMMIT TRAN