I'm building a procedure that runs several steps, after each step I want to check and see if an error happened. If the procedure errors out I would like to update a table with the current status of the ErrorCode so that I can easily find where it went awry

Something like

@LastRun DateTime,
@RunStart DateTime,
@RunStop DateTime,
@ErrorCode Int

Set @LastRun = 'LastComplete from tblprocess where processID = 1
IF @@ERROR <>0 Set @ErrorCode = 10

Update tblProcess.LastRunStart = @RunStart where processID = 1
IF @@ERROR <>0 Set @ErrorCode = 20

Create Table tmpTempDays
CareDate DateTime NOT NULL,
ProviderNumber Varchar(20) NOT NULL,
AttendanceTypeID Int NOT NULL,
ChildID Int NOT NULL,)
IF @@ERROR <> 0 Set @ErrorCode = 30

[More Steps]
IF @@ERROR <> 0 Set @ErrorCode = 0

Update tblProcess.LastRunEnd = GetDate() where processID = 1
Update tblProcess.ErrorCode = @ErrorCode where processID = 1

The question I have is how do I update tblprocess.ErrorCode if the process errors out after @ErrorCode is Set to 30 without running the rest of the process?