[dbo].[DeletePMImportStatement]
create procedure [dbo].[DeletePMImportStatement]
@inPMImportHeaderID int,
@inHadError bit
as
set nocount on
declare @theOkToDelete bit = 1
if( @inHadError = 1 )
begin
if( 'true' = isnull( ( select [Value] from GlobalSystemOption where [Name] = 'KeepPMImportHeaderAndDetailsOnError' ), '' ) )
begin
set @theOkToDelete = 0
end
end
if( @theOkToDelete = 1 )
begin
delete from PMImportDetailError
from PMImportDetail
inner join PMImportDetailError on PMImportDetailError.PMImportDetailFID = PMImportDetail.PMImportDetailID
where PMImportDetail.PMImportHeaderFID = @inPMImportHeaderID
delete from PMImportDetailDist
from PMImportDetail
inner join PMImportDetailDist on PMImportDetailDist.PMImportDetailFID = PMImportDetail.PMImportDetailID
where PMImportDetail.PMImportHeaderFID = @inPMImportHeaderID
delete from PMImportDetail
where PMImportDetail.PMImportHeaderFID = @inPMImportHeaderID
delete from PMImportHeader
where PMImportHeaderID = @inPMImportHeaderID
end
GO
GRANT EXECUTE ON [dbo].[DeletePMImportStatement] TO [MssExec]
GO