Files
DP44/DataPRO_sql/dbo.sp_SensorsDigitalInInsert.StoredProcedure.sql
2026-04-17 14:55:32 -04:00

119 lines
4.0 KiB
Transact-SQL
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
USE [DataPRO]
GO
/****** Object: StoredProcedure [dbo].[sp_SensorsDigitalInInsert] Script Date: 6/19/2018 12:25:10 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_SensorsDigitalInInsert]
@SerialNumber nvarchar(50)
,@SettingMode int
,@ScaleMultiplier nvarchar(50)
,@LastModified datetime
,@LastModifiedBy nvarchar(50)
,@eId nvarchar(50)
,@UserValue1 nvarchar(255)
,@UserValue2 nvarchar(255)
,@UserValue3 nvarchar(255)
,@UserTags varbinary(max)
,@MeasurementUnit nvarchar(50)
,@FilterClass nvarchar(50)
,@new_id int output
,@errorNumber int output
,@errorMessage nvarchar(250) output
AS
BEGIN
set @errorNumber = 0
set @errorMessage = space(0)
if(@SerialNumber is null)
begin
set @errorNumber = 15600
set @errorMessage = 'An invalid parameter or option was specified for procedure'
end
else
begin
if(exists(select SerialNumber from v_SensorSerialNumber where SerialNumber = @SerialNumber))
begin
set @errorMessage = 'The sensor serial mumber - ' + ltrim(rtrim(@SerialNumber)) + ' is not unique';
set @errorNumber = -1
end
else
begin
INSERT INTO [dbo].[SensorsDigitalIn]
([SerialNumber]
,[SettingMode]
,[ScaleMultiplier]
,[LastModified]
,[LastModifiedBy]
,[eId]
,[UserValue1]
,[UserValue2]
,[UserValue3]
,[UserTags]
,[MeasurementUnit]
,[FilterClass])
VALUES
(@SerialNumber
,@SettingMode
,@ScaleMultiplier
,@LastModified
,@LastModifiedBy
,isnull(@eId, space(0))
,@UserValue1
,@UserValue2
,@UserValue3
,@UserTags
,@MeasurementUnit
,@FilterClass)
set @new_id = scope_identity();
exec dbo.sp_SensorInsert @new_id, 1 /* see table dbo.SensorsType */
end
end
end