USP_DATAFORMTEMPLATE_EDIT_MKTOURCECODE_2

The save procedure used by the edit dataform template "Source Code Edit Form 2".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN The input ID parameter indicating the ID of the record being edited.
@NAME nvarchar(100) IN Name
@SITEID uniqueidentifier IN Site
@ISDEFAULT bit IN Use this layout as the default
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@DESCRIPTION nvarchar(255) IN Description

Definition

Copy

CREATE procedure dbo.[USP_DATAFORMTEMPLATE_EDIT_MKTOURCECODE_2]
(
  @ID uniqueidentifier,
  @NAME nvarchar(100),
  @SITEID uniqueidentifier,
  @ISDEFAULT bit,
  @CHANGEAGENTID uniqueidentifier = null,
  @DESCRIPTION nvarchar(255)
)
as                
  set nocount on;

  declare @CURRENTDATE datetime
  declare @CURRENTSITEID uniqueidentifier;

  set @CURRENTDATE = getdate();

  begin try
    if @CHANGEAGENTID is null  
      exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output;

    -- get the current default template
    if @ISDEFAULT <> 0
      begin
        declare @DEFAULTID uniqueidentifier;

        select top 1 @DEFAULTID = [ID] from dbo.[MKTSOURCECODE]  where ([SITEID] = @SITEID or (@SITEID is null and [SITEID] is null)) and [ISDEFAULT] <> 0;

        if not @DEFAULTID is null
          if @DEFAULTID <> @ID 
            update dbo.[MKTSOURCECODE] set [ISDEFAULT] = 0, [CHANGEDBYID] = @CHANGEAGENTID, [DATECHANGED] = @CURRENTDATE where [ID] = @DEFAULTID;
      end

    update dbo.[MKTSOURCECODE] set 
      [NAME] = @NAME,
      [DESCRIPTION] = @DESCRIPTION,
      [ISDEFAULT] = @ISDEFAULT,
      [SITEID] = @SITEID,
      [CHANGEDBYID] = @CHANGEAGENTID,
      [DATECHANGED] = @CURRENTDATE
    where [ID] = @ID;

  end try

  begin catch
    exec dbo.[USP_RAISE_ERROR]
    return 1;
  end catch

  return 0;