Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Handling Errors on DML

Author  Topic 

sanjay1909
Starting Member

14 Posts

Posted - 2004-09-30 : 01:49:44
Hi all,

The below Stored procedure gives be error on execution and does not handle. I am trying to insert a duplicate record in mytable which should generate a system constraint error. On error it should insert in ErrorTable. But it halts on error.
Please give some JaanLeva solution.

CREATE PROCEDURE [dbo].[san] AS

BEGIN
INSERT INTO mytable
(column1)
VALUES
('sanjay')

IF (@@ERROR <> 0)
BEGIN
SELECT @ErrFlag = 1
SELECT @CommitFlag = 1
SELECT @ErrNo = @@ERROR
SELECT @ErrMsg = 'Duplicate Rec - ' & @RecNo

INSERT INTO ERRORTABLE
(ERRS_ErrorNo, ERRS_ErrorDesc)
VALUES
(@@ERROR, 'DUPLICATE RECORD EXISTS')
END
END
GO
Regards
Sanjay Masawan
sanjaymasawan@yahoo.com

Regards
Sanjay Masawan
sanjaymasawan@yahoo.com
   

- Advertisement -