UFN_LEDGERACCOUNT_ACCOUNTISUNIQUE
Ensures that the combination of account segments is not already in use.
Return
Return Type |
---|
bit |
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@ACCOUNTSEGMENTS | xml | IN | |
@ACCOUNTID | uniqueidentifier | IN |
Definition
Copy
CREATE function dbo.UFN_LEDGERACCOUNT_ACCOUNTISUNIQUE(@ACCOUNTSEGMENTS xml, @ACCOUNTID uniqueidentifier = null)
returns bit
with execute as caller
as begin
declare @PDACCOUNTSYSTEMID uniqueidentifier = '4B121C2C-CCE6-440D-894C-EA0DEF80D50B'
declare @SEPARATOR nvarchar(1);
select top 1 @SEPARATOR = SEPARATOR from dbo.PDACCOUNTSTRUCTURE where PDACCOUNTSYSTEMID = @PDACCOUNTSYSTEMID and ISBASICGL=0;
declare @ACCOUNTSTRING nvarchar(130)
set @ACCOUNTSTRING =
(select
coalesce(SHORTDESCRIPTION+@SEPARATOR, '')
from
dbo.PDACCOUNTSEGMENTVALUE
inner join dbo.UFN_LEDGERACCOUNT_GETACCOUNTSEGMENTS_FROMITEMLISTXML(@ACCOUNTSEGMENTS) T1 on T1.DATAELEMENTID = PDACCOUNTSEGMENTVALUE.ID
inner join dbo.PDACCOUNTSTRUCTURE on PDACCOUNTSEGMENTVALUE.PDACCOUNTSTRUCTUREID = PDACCOUNTSTRUCTURE.ID
order by
PDACCOUNTSTRUCTURE.SEGMENTSEQUENCE
for xml path(''), type).value('.','nvarchar(130)')
set @ACCOUNTSTRING = substring(@ACCOUNTSTRING, 1, len(@ACCOUNTSTRING)-1) -- Remove the trailing hyphen
if exists (
select
1
from
dbo.GLACCOUNT
where
(@ACCOUNTID is null or ID != @ACCOUNTID)
and
ACCOUNTSTRING = @ACCOUNTSTRING
) return 0;
return 1;
end