DECLARE @FE as varchar(3) SET @FE= 'GEN' -- Start Transaction ----------------------------------------------------------------------------------------------------------------------------------------- BEGIN TRANSACTION --SELECT @MatterList = ( SELECT code FROM matters where FEcode = @FE) --SELECT @intDiaryDelActionID = ( SELECT actionid FROM diary where casecode = ( SELECT code FROM matters where FEcode = @FE)) --IF @@error <> 0 GOTO ErrorCatch SELECT COUNT(code) FROM matters where FEcode = @FE -- Delect Diary delegation Delete [DiaryDelegations] where actionid IN ( SELECT actionid FROM diary where casecode IN ( SELECT code FROM matters where FEcode = @FE)) IF @@error <> 0 GOTO ErrorCatch -- Delect Diary Attachements Delete [DiaryAttachments] where casecode IN ( SELECT code FROM matters where FEcode = @FE) IF @@error <> 0 GOTO ErrorCatch -- Case Contacts Delete [CaseContacts] where casecode IN ( SELECT code FROM matters where FEcode = @FE) IF @@error <> 0 GOTO ErrorCatch -- CaseUDFAnswers Delete [CaseUDFAnswers] where casecode IN ( SELECT code FROM matters where FEcode = @FE) IF @@error <> 0 GOTO ErrorCatch -------------------------------------------------------------------------------------------------------------------------------------- -- Delete Diary Delete Diary where CASECODE IN ( SELECT code FROM matters where FEcode = @FE) IF @@error <> 0 GOTO ErrorCatch -- CaseUDFAnswers Delete [CaseMaster] where CSCODE IN ( SELECT code FROM matters where FEcode = @FE) IF @@error <> 0 GOTO ErrorCatch -- TimeDayBook Delete [TimeDaybook] where MATTER IN ( SELECT code FROM matters where FEcode = @FE) IF @@error <> 0 GOTO ErrorCatch -- TimeEntry Delete [TimeEntry] where MATTER IN ( SELECT code FROM matters where FEcode = @FE) IF @@error <> 0 GOTO ErrorCatch -- Delete Diary Delete Matters where FECode = @FE IF @@error <> 0 GOTO ErrorCatch SELECT count(code) FROM matters where FEcode = @FE -- Commit ROLLBACK --COMMIT IF @@error <> 0 GOTO ErrorCatch -- Exit ExitPoint: Return -- Error Handling ErrorCatch: ROLLBACK goto ExitPoint