CREATE PROCEDURE usp_InsertEmployee@ flag bit output, --
return 0
for fail, 1
for success@ EmpID int, @Name varchar(50), @Salary int, @Address varchar(100)
AS
BEGIN
BEGIN TRANSACTION
BEGIN TRY
Insert into Employee(EmpID, Name, Salary, Address) Values(@EmpID, @Name, @Salary, @Address)
set@ flag = 1;
IF@@ TRANCOUNT > 0
BEGIN commit TRANSACTION;
END
END TRY
BEGIN CATCH
IF@@ TRANCOUNT > 0
BEGIN rollback TRANSACTION;
END
set@ flag = 0;
END CATCH
END - Execute above created procedure to insert rows into table
Declare@ flag bit
EXEC usp_InsertEmployee@ flag output, 4, 'Deepak', 14000, 'Noida'
if@ flag = 1
print 'Successfully inserted'
else print 'There is some error'This code snippet for Insert Stored procedure using flag
