38 lines
4.6 KiB
Plaintext
38 lines
4.6 KiB
Plaintext
ALTER PROCEDURE [dbo].[sp_SensorsAnalogDelete]
|
|
@SensorId INT = NULL,
|
|
@SerialNumber NVARCHAR (50) = NULL,
|
|
@errorNumber int output,
|
|
@errorMessage nvarchar(250) output
|
|
AS
|
|
BEGIN
|
|
set @errorNumber = 0
|
|
set @errorMessage = ''
|
|
|
|
IF( @SensorId IS NULL)
|
|
BEGIN
|
|
IF NULLIF(@SerialNumber,'') IS NULL
|
|
BEGIN
|
|
DELETE A FROM [dbo].[SensorChangeHistory] AS A INNER JOIN [dbo].[Sensors] as B on A.SensorId=B.id INNER JOIN [dbo].SensorsType AS C on C.TypeId=B.SensorType WHERE C.SensorType='Analog'
|
|
DELETE A FROM [dbo].[SensorsAnalog] AS A INNER JOIN [dbo].[Sensors] AS B ON A.SensorId=B.id INNER JOIN [dbo].SensorsType AS C ON C.TypeId=B.SensorType WHERE C.SensorType='Analog'
|
|
DELETE A FROM [dbo].[Sensors] AS A INNER JOIN [dbo].[SensorsType] AS B on A.SensorType=B.TypeId WHERE B.SensorType='Analog'
|
|
END
|
|
ELSE
|
|
BEGIN
|
|
SELECT @SensorId = A.[Id] FROM [dbo].[Sensors] AS A INNER JOIN [dbo].[SensorsType] AS B ON A.SensorType=B.TypeId WHERE B.SensorType='Analog' AND A.SerialNumber=@SerialNumber
|
|
DELETE A FROM [dbo].[SensorChangeHistory] AS A INNER JOIN [dbo].[Sensors] as B on A.SensorId=B.id INNER JOIN [dbo].SensorsType AS C on C.TypeId=B.SensorType WHERE C.SensorType='Analog' and A.SensorId=@SensorId
|
|
DELETE A FROM [dbo].[SensorsAnalog] AS A INNER JOIN [dbo].[Sensors] AS B ON A.SensorId=B.id INNER JOIN [dbo].SensorsType AS C ON C.TypeId=B.SensorType WHERE C.SensorType='Analog' AND A.SensorId=@SensorId
|
|
DELETE A FROM [dbo].[Sensors] AS A INNER JOIN [dbo].[SensorsType] AS B on A.SensorType=B.TypeId WHERE B.SensorType='Analog' AND A.id=@SensorId
|
|
END
|
|
END
|
|
ELSE
|
|
BEGIN
|
|
DELETE A FROM [dbo].[SensorChangeHistory] AS A INNER JOIN [dbo].[Sensors] AS B ON A.SensorId=B.id INNER JOIN [dbo].SensorsType AS C ON C.TypeId=B.SensorType WHERE C.SensorType='Analog' AND A.SensorId=@SensorId
|
|
DELETE A FROM [dbo].[SensorsAnalog] AS A INNER JOIN [dbo].[Sensors] AS B ON A.SensorId=B.id INNER JOIN [dbo].SensorsType AS C ON C.TypeId=B.SensorType WHERE C.SensorType='Analog' AND A.SensorId=@SensorId
|
|
DELETE A FROM [dbo].[Sensors] AS A INNER JOIN [dbo].[SensorsType] AS B on A.SensorType=B.TypeId WHERE B.SensorType='Analog' AND A.id=@SensorId
|
|
END
|
|
IF(@@error != 0)
|
|
BEGIN
|
|
SET @errorNumber = error_number()
|
|
SET @errorMessage = error_message()
|
|
END
|
|
END |