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

130 lines
4.8 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_TestChannelSettingsInsert] Script Date: 6/26/2018 3:51:46 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_TestChannelSettingsInsert]
@TestSetupId int = 0
,@TestSetupName nvarchar(255)
,@TestObjectId int = 0
,@TestObjectName nvarchar(255)
,@TemplateChannelId int = 0
,@ChannelId nvarchar(255)
,@Setting nvarchar(255)
,@SensorSerialNumber nvarchar(255)
,@SensorId int = 0
,@Disabled bit
,@new_id int =0 output
,@errorNumber int output
,@errorMessage nvarchar(250) output
AS
BEGIN
set @errorNumber = 0; set @errorMessage = space(0); set @new_id = 0;
begin try
if(@TestSetupName is null)
begin
set @errorMessage = 'An invalid parameter or option was specified for procedure'
set @errorNumber = 15600
end
else
begin
if(@TestSetupId = 0)
begin
set @TestSetupId = dbo.foo_IdGetTestSetup(@TestSetupName)
end
if(@TestObjectId=0)
begin
set @TestObjectId = dbo.foo_IdGetTestObject(@TestObjectName)
end
if(@SensorId=0)
begin
set @SensorId = dbo.foo_IdGetSensor(@SensorSerialNumber)
end
if(@TemplateChannelId =0)
begin
declare @TemplateId int
set @TemplateId = dbo.foo_IdGetTestObjectTemplate(@TestObjectName)
set @TemplateChannelId = dbo.foo_IdGetTemplateChannel( @TemplateId, @SensorId, @TestObjectId, @ChannelId)
end
if(@TestSetupId = 0 or @TestObjectId=0 or @SensorId=0 or @TemplateChannelId =0)
begin
set @errorMessage = 'Could not find testup, group, sensor, or channel'
set @errorNumber = 12345
end
else
begin
insert into [dbo].[TestChannelSettings]
([TestSetupId]
,[TestObjectId]
,[TemplateChannelId]
,[ChannelId]
,[Setting]
,[SensorId]
,[Disabled])
values
(@TestSetupId
,@TestObjectId
,@TemplateChannelId
,@ChannelId
,@Setting
,@SensorId
,@Disabled)
set @new_id = scope_identity();
end
end
end try
begin catch
set @errorMessage = error_message()
set @errorNumber = error_number()
end catch;
END