|
skaluva
Starting Member
17 Posts |
Posted - 2002-07-09 : 17:46:13
|
| Hi All;The below is the code I have in one of my stored proceedures. I am calling this stored proceedure as a scheduled job. You can see that in my code I am using @@Error to handle errors. Though I am doing error handle in this SQL job is showing me as job failed as SQL Server spitting out the critical error message as given below.Msg 2627, Sev 14: Violation of UNIQUE KEY constraint 'IX_tblEmployees'. Cannot insert duplicate key in object 'tblEmployees'. [SQLSTATE 23000]Msg 3621, Sev 14: The statement has been terminated. [SQLSTATE 01000]Msg 0, Sev 0: Associated statement is not prepared [SQLSTATE HY007]This message is comming due to the execution of Insert statement into tblEmployees. Please help me how to suppress this system error messages?Begin -- Case 1 Declare cusrNewEmployees Insensitive cursor for SELECT BranchID, Left(FirstName, 20) as FirstName, Left(LastName, 20) as LastName, MidInit, IsNull(RegRate, 0), IsNull(OTRate, 0), SSN5 , tblEmpSpec.SpecID as SpecID from tblInput_Employees Left Outer Join tblEmpSpec on tblEmpSpec.SpecCode = tblInput_Employees.GroupID Where RTrim(BranchID) + ' - ' + RTrim(FirstName) + IsNull(MidInit, ' ') + RTrim(LastName) + ' - ' + RTrim(SSN5) Not In (Select RTrim(BranchID) + ' - ' + RTrim(EmpFirstName) + IsNull(EmpMidInit, ' ') + RTrim(EmpLastName) + ' - ' + RTrim(SSN5) From tblEmployees ) Open cusrNewEmployees Fetch next from cusrNewEmployees into @sBranchID, @sFirstName, @sLastName, @sMidInit, @mRate, @mOTRate, @sSSN4, @iSpecID While @@FEtch_Status = 0 Begin Begin If Len(@sLastName) > 7 Select @sUID = Left(@sLastName, 7) Else Select @sUID = @sLastName Select @sUID = @sUID + Left(@sFirstName, 2) Select @sTagSSN = Convert(Char(2), Convert(TinyInt, SubString(@sSSN4, 1, 1)) + Convert(TinyInt, SubString(@sSSN4, 2, 1)) + Convert(TinyInt,SubString(@sSSN4, 3, 1)) + Convert(TinyInt,SubString(@sSSN4, 4, 1))) If Len(@sTagSSN) < 2Select @sTagSSN = '0' + @sTagSSNSelect @sUID = Rtrim(@sBranchID) + @sUID + @sTagSSN Select @iSpecID = Case @iSpecIDWhen 7 then 13When 11 then 7Else@iSpecIDEndInsert into tblEmployees (BranchID, SpecID, EmpFirstName, EmpMidInit, EmpLastName, EmpRegRate, EmpOTRate, SSN5, UserName, pwd) Values (@sBranchID, @iSpecID, @sFirstName, @sMidInit, @sLastName, @mRate, @mOTRate, @sSSN4, @sUID, @sUID ) If @@Error > 0 Begin Insert into tblData_Import_Log (JobID, JobName, Error_Description, JobType) values ( IsNull(@sLastName, ''), RTrim(IsNull(@sFirstName, '')) + '-SSN4=' + @sSSN4 + 'BranchID=' + RTrim(@sBranchID) , 'Unique Key violation error on User ID. Please make sure the data of the record is not repeated.', 'employee') EndFetch next from cusrNewEmployees into @sBranchID, @sFirstName, @sLastName, @sMidInit, @mRate, @mOTRate, @sSSN4, @iSpecID End Close cusrNewEmployeesDeallocate cusrNewEmployeesEnd -- End of Case 1Thanks in Hand,-- Sree |
|