Stored Procedures [dbo].[DeletePMImportStatement]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)
@inPMImportHeaderIDint4
@inHadErrorbit1
Permissions
TypeActionOwning Principal
GrantExecuteMssExec
SQL Script
/*
* Removes the PMImportHeader and its underlying details, distributions and errors.
*
* @inPMImportHeaderID the primary key for the PMImportHeader record to be removed.
* @inHadError is 1 if we are cleaning up after an unexpected error otherwise 0.
*/

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
Uses