[dbo].[BATCheckCustomerStatus]
CREATE PROCEDURE [dbo].[BATCheckCustomerStatus]
@inBATSessionID varchar(50),
@inObjectTable varchar(20) = null,
@inObjectID int = null
as
set nocount on
declare @theErrorCode int = 0
declare @theBlankSessionID varchar(50) = ''
declare @theBATProcessTqble varchar(50) = 'BATProcess'
declare @theInvalidCustomers table
(
RecordID int identity( 1, 1 ) not null,
CustomerNumber varchar(15) null,
ErrorCodeID int not null,
[Source] varchar(50),
SourceRecord int
)
declare @theErrorCounter int
declare @theRecordID int = 1
declare @theCustomerNumber varchar(15)
declare @theErrorCodeID int
declare @theSource varchar(50)
declare @theSourceRecord int
insert into @theInvalidCustomers
(
CustomerNumber,
ErrorCodeID,
[Source],
SourceRecord
)
select
CustomerNumber = rtrim( BATProcess.CustomerNumber ),
ErrorCodeID = case
when RM00101.CUSTNMBR is null then 338
when RM00101.INACTIVE = 1 then 339
when RM00101.HOLD = 1 then 340
end,
[Source] = BATProcess.[Source],
SourceRecord = BATProcess.SourceRecord
from BATProcess
left outer join RM00101_Synonym as RM00101 on RM00101.CustNmbr = BATProcess.CustomerNumber
where BATProcess.BATSessionID = @inBATSessionID and
BATProcess.CustomerNumber is not null and
(
RM00101.CUSTNMBR is null or
RM00101.INACTIVE = 1 or
RM00101.HOLD = 1
)
set @theErrorCounter = ( select count(*) from @theInvalidCustomers )
if( @theErrorCounter > 0 )
begin
while( @theRecordID <= @theErrorCounter )
begin
select
@theCustomerNumber = CustomerNumber,
@theErrorCodeID = ErrorCodeID,
@theSource = [Source],
@theSourceRecord = SourceRecord
from @theInvalidCustomers
where RecordID = @theRecordID
exec spBATRecordError
@theBlankSessionID,
@theSource,
@theSourceRecord,
@theErrorCodeID,
@inObjectTable,
@inObjectID,
@theCustomerNumber
set @theRecordID = @theRecordID + 1
end
set @theErrorCode = 1
end
return @theErrorCode
GO
GRANT EXECUTE ON [dbo].[BATCheckCustomerStatus] TO [MssExec]
GO