Create PROC InsertUpdatetemplate
-- This proc is used for insert or update records
-- it is simple sp with roll back transaction
-- so we have to just upload this format
(
)
as
IF (exists(SELECT * FROM tablename WHERE condition))
BEGIN
--Update
BEGIN TRY
BEGIN TRAN
UPDATE qery
COMMIT TRAN
RETURN 1
END TRY
BEGIN CATCH
ROLLBACK TRAN
SELECT ERROR_NUMBER()[ERROR NUMBER],ERROR_LINE()[ERROR IN LINE],ERROR_PROCEDURE()[ERROR IN PROCEDURE],ERROR_MESSAGE()[ERROR
MESSAGE]
RETURN 0
END CATCH
END
ELSE
BEGIN
-- Insert
BEGIN TRY
BEGIN TRAN
insert query
COMMIT TRAN
RETURN 1
END TRY
BEGIN CATCH
ROLLBACK TRAN
SELECT ERROR_NUMBER()[ERROR NUMBER],ERROR_LINE()[ERROR IN LINE],ERROR_PROCEDURE()[ERROR IN PROCEDURE],ERROR_MESSAGE()[ERROR
MESSAGE]
RETURN 0
END CATCH
END
No comments:
Post a Comment