UFN_GLACCOUNT_VERIFYACCOUNTNUMBER2
Checks the account number for proper formatting.
Return
Return Type |
---|
bit |
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@AccountNumber | nvarchar(100) | IN | |
@ID | uniqueidentifier | IN |
Definition
Copy
CREATE function [dbo].[UFN_GLACCOUNT_VERIFYACCOUNTNUMBER2](@AccountNumber nvarchar(100),@ID uniqueidentifier)
returns bit
as
begin
declare @AccountLength int = (select sum(LENGTH)+sum(case SEPARATORCODE when 6 then 0 else 1 end)-(select top 1 case SEPARATORCODE when 6 then 0 else 1 end from dbo.PDACCOUNTSTRUCTURE where PDACCOUNTSYSTEMID = @ID order by SEQUENCE desc) from dbo.PDACCOUNTSTRUCTURE where PDACCOUNTSYSTEMID=@ID)
if @AccountLength != len(@AccountNumber) or @AccountLength is null
return (0)
declare @SepPosition int = 0
declare @SegLength int
declare @SeqNumber int = 0
declare @SepCode int
declare @SepChar nchar(1) = '.' --dummy value to get into the loop below
while @SepChar is not null
begin
set @SeqNumber += 1
set @SepChar = NULL
select @SepChar = SEPARATOR, @SegLength = LENGTH, @SepCode = SEPARATORCODE from dbo.PDACCOUNTSTRUCTURE where SEQUENCE = @SeqNumber and PDACCOUNTSYSTEMID=@ID
set @SepPosition += @SegLength + 1
if patindex('%[^0-9,^a-z,^A-Z]%',substring(@AccountNumber,@SepPosition - @SegLength,@SegLength)) > 0
return (0)
if patindex('%[,]%',substring(@AccountNumber,@SepPosition - @SegLength,@SegLength)) > 0
return (0)
if @SepCode != 6
begin
if substring(@AccountNumber,@SepPosition,1) != @SepChar and @SepPosition < @AccountLength
return (0)
end
else
set @SepPosition -= 1
end
return (1)
end