Files
DP44/DataPRO_sql/dbo.sp_TestSetupObjectsDelete.StoredProcedure.sql

92 lines
4.1 KiB
MySQL
Raw Permalink Normal View History

2026-04-17 14:55:32 -04:00
<EFBFBD><EFBFBD>IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_TestSetupObjectsDelete]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[sp_TestSetupObjectsDelete]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_TestSetupObjectsDelete]') AND type in (N'P', N'PC'))
BEGIN
EXEC dbo.sp_executesql @statement = N'CREATE PROCEDURE [dbo].[sp_TestSetupObjectsDelete] AS'
END
GO
ALTER PROCEDURE [dbo].[sp_TestSetupObjectsDelete]
@TestObjectId int = 0
,@TestObjectName varchar(255) = null
,@errorNumber int output
,@errorMessage nvarchar(250) output
AS
BEGIN
set @errorNumber = 0; set @errorMessage = space(0);
if(@TestObjectId =0 and @TestObjectName is not null)
begin
set @TestObjectId = dbo.foo_IdGetTestObject(@TestObjectName)
end
if(@TestObjectId != 0)
begin
begin transaction [tTestSetupObjectsDelete]
delete from [dbo].[TestObjectHardware] where TestObjectId = @TestObjectId
delete from [dbo].[TestObjectSensors] where TestObjectId = @TestObjectId
delete from [dbo].[TestObjectChannelSettings] where TestObjectId = @TestObjectId
declare @TemplateId int
select @TemplateId = TemplateId from [dbo].[TestObjects] where TestObjectId = @TestObjectId
delete from [dbo].[TestChannelSettings] where TestObjectId = @TestObjectId
delete from [dbo].[TemplateChannels] where TemplateId = @TemplateId
delete from [dbo].[TemplateZones] where TemplateId = @TemplateId
delete from [dbo].[TestSetupObjects] where TestObjectId = @TestObjectId
delete from [dbo].[TestObjects] where TestObjectId = @TestObjectId
delete from [dbo].[TestObjectTemplates] where TemplateId = @TemplateId
commit transaction [tTestSetupObjectsDelete]
if(@@error != 0)
begin
set @errorNumber = error_number()
set @errorMessage = error_message()
rollback transaction [tTestSetupObjectsDelete]
end
end
END
GO