ALTER PROCEDURE [dbo].[sp_SensorsDelete] @SensorId INT, @SensorType INT, @errorNumber INT OUTPUT, @errorMessage NVARCHAR(255) OUTPUT AS BEGIN SET NOCOUNT ON; SET @errorNumber=0 SET @errorMessage='' begin try begin transaction [tDeleteSensors] exec [dbo].[sp_TestSetupsMarkIncomplete] @sensorId, 'Some channels have no sensor assigned.', null, @errorNumber output ,@errorMessage output exec [dbo].[sp_SensorCalibrationsDelete] null, @sensorId, 'not used', null, null, @errorNumber output, @errorMessage output UPDATE [dbo].Channels SET [SensorId] = null WHERE [SensorId]=@SensorId DELETE FROM [dbo].[SensorChangeHistory] where [SensorID] = @SensorId DELETE FROM [dbo].[SensorsAnalog] where [SensorId] = @SensorId DELETE FROM [dbo].[SensorsDigitalIn] where [SensorId] = @SensorId DELETE FROM [dbo].[SensorsDigitalOut] where [SensorId] = @SensorId DELETE FROM [dbo].[SensorsSquib] where [SensorId] = @SensorId DELETE FROM [dbo].[Sensors] where id = @SensorId commit transaction [tDeleteSensors] end try begin catch rollback transaction [tDeleteSensors] set @errorMessage = error_message() set @errorNumber = error_number() end catch END