Files
DP44/DataPRO/Modules/Database/DatabaseMigrationScripts/.svn/pristine/3d/3d1429d908b5711e3d745e9f9bed2877d2475fb0.svn-base

35 lines
2.5 KiB
Plaintext
Raw Normal View History

2026-04-17 14:55:32 -04:00
<EFBFBD><EFBFBD>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