44 lines
2.0 KiB
Plaintext
44 lines
2.0 KiB
Plaintext
ALTER PROCEDURE [dbo].[sp_SensorCalibrationsDelete]
|
|
@Id int = null,
|
|
@SensorId int = null,
|
|
@SensorSerialNumber nvarchar(50) = null,
|
|
@CalibrationDate datetime = null,
|
|
@ModifiedDate datetime = null,
|
|
@errorNumber int output,
|
|
@errorMessage nvarchar(250) output
|
|
AS
|
|
BEGIN
|
|
set @errorNumber = 0
|
|
set @errorMessage = space(0)
|
|
|
|
if( @Id IS NULL )
|
|
BEGIN
|
|
IF( @SensorId IS NULL )
|
|
BEGIN
|
|
SELECT @SensorId = A.[id] from [dbo].[Sensors] AS A INNER JOIN [dbo].[SensorsType] AS B ON A.SensorType=B.TypeId WHERE A.[SerialNumber]=@SensorSerialNumber AND B.SensorType='Analog';
|
|
END
|
|
END
|
|
ELSE
|
|
BEGIN
|
|
SELECT @SensorId = [SensorId] FROM [dbo].[SensorCalibrations] WHERE [SensorCalibrationId]=@Id
|
|
END
|
|
|
|
declare @tSensorCalibrations table(SensorCalibrationId int)
|
|
declare @tSensorCalibrationRecords table(SensorCalibrationRecordId int)
|
|
|
|
insert into @tSensorCalibrations (SensorCalibrationId)
|
|
select SensorCalibrationId from [dbo].[SensorCalibrations]
|
|
where
|
|
(@SensorSerialNumber is null or SensorId = @SensorId)
|
|
and (@CalibrationDate is null or CalibrationDate = @CalibrationDate)
|
|
and (@ModifiedDate is null or ModifyDate = @ModifiedDate)
|
|
|
|
insert into @tSensorCalibrationRecords (SensorCalibrationRecordId) select SensorCalibrationRecordId from SensorCalibrationRecord where SensorCalibrationId in (select SensorCalibrationId from @tSensorCalibrations)
|
|
|
|
|
|
delete from [dbo].[SensorCalibrationRecordIRTracc] where SensorCalibrationRecordId in (select SensorCalibrationRecordId from @tSensorCalibrationRecords)
|
|
delete from [dbo].[SensorCalibrationRecordPolynomial] where SensorCalibrationRecordId in (select SensorCalibrationRecordId from @tSensorCalibrationRecords)
|
|
|
|
delete from [dbo].[SensorCalibrationRecord] where SensorCalibrationId in (select SensorCalibrationId from @tSensorCalibrations)
|
|
delete from [dbo].[SensorCalibrations] where SensorCalibrationId in (select SensorCalibrationId from @tSensorCalibrations)
|
|
END |