USP_DATAFORMTEMPLATE_ADD_PDACCOUNTSTRUCTURE

The save procedure used by the add dataform template "Account Structure Add Form".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier INOUT The output parameter indicating the ID of the record added.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@DESCRIPTION nvarchar(100) IN Segment name
@SEQUENCE int IN Sequence
@LENGTH tinyint IN Length
@PDACCOUNTTABLESAVAILABLEFORSEGMENTID uniqueidentifier IN Calculated using
@SEGMENTTYPE tinyint IN Segment type
@SEPARATORCODE tinyint IN Separator

Definition

Copy

CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_PDACCOUNTSTRUCTURE
(
    @ID uniqueidentifier = null output,
    @CHANGEAGENTID uniqueidentifier = null,
    @DESCRIPTION nvarchar(100) = null,
    @SEQUENCE int = 0,
    @LENGTH tinyint = 0,
    @PDACCOUNTTABLESAVAILABLEFORSEGMENTID uniqueidentifier = null,
    @SEGMENTTYPE tinyint = 3,
    @SEPARATORCODE tinyint = 1    
)
as

set nocount on;

if @ID is null
    set @ID = newid()

if @CHANGEAGENTID is null  
    exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output

declare @CURRENTDATE datetime

set @CURRENTDATE = getdate()
select @SEQUENCE = dbo.UFN_PDACCOUNTSTRUCTURE_GETTABLENUMBER()
Select @SEGMENTTYPE = case when ISCODETABLE < 3 then 3 else 4 end  from PDACCOUNTTABLESAVAILABLEFORSEGMENT where ID = @PDACCOUNTTABLESAVAILABLEFORSEGMENTID
if @SEPARATORCODE is null 
    set @SEPARATORCODE = 1

begin try
    -- handle inserting the data
  declare @MAXCOLUMN int;
  select @MAXCOLUMN = isnull(max(SEGMENTCOLUMN),1) from dbo.PDACCOUNTSTRUCTURE;

    insert into dbo.PDACCOUNTSTRUCTURE
        (ID, DESCRIPTION, SEQUENCE, LENGTH, PDACCOUNTTABLESAVAILABLEFORSEGMENTID, SEGMENTTYPE, SEPARATORCODE, PDACCOUNTSYSTEMID, ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED, SEGMENTCOLUMN, SEGMENTSEQUENCE)
    values
        (@ID, @DESCRIPTION, @SEQUENCE, @LENGTH, @PDACCOUNTTABLESAVAILABLEFORSEGMENTID,@SEGMENTTYPE,@SEPARATORCODE, '4B121C2C-CCE6-440D-894C-EA0DEF80D50B' ,@CHANGEAGENTID, @CHANGEAGENTID, @CURRENTDATE, @CURRENTDATE, @MAXCOLUMN, @SEQUENCE)

end try

begin catch
    exec dbo.USP_RAISE_ERROR
    return 1
end catch

return 0