IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'stor.[sp_DeleteSgtinsProcess]') AND type in (N'P', N'PC'))
DROP PROCEDURE stor.[sp_DeleteSgtinsProcess]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'dbo.[sp_DeleteSgtinsProcess]') AND type in (N'P', N'PC'))
DROP PROCEDURE dbo.[sp_DeleteSgtinsProcess]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      Vitacore (с) Anatoliy
-- Create date: 2021 03 09
-- Description: Удаление из накладной sgtins
-- =============================================
CREATE PROCEDURE stor.[sp_DeleteSgtinsProcess]
    @InvoiceId uniqueidentifier
AS
BEGIN
	if(exists(select * from STOR.T_STORAGE_INVOICE where InvoiceID = @InvoiceId and State = 0))
	Begin
		delete from STOR.T_SGTINS where StorageInvoice = @InvoiceId
	end
END