USP_DATAFORMTEMPLATE_EDITLOAD_MKTSEGMENTATIONTESTSEGMENT_DRAGDROPINSERT

The load procedure used by the edit dataform template "Marketing Effort Test Segment Drag and Drop Edit Form"

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN The input ID parameter used to load the fields defined on the form.
@DATALOADED bit INOUT Output parameter indicating whether or not data was actually loaded.
@TESTSEGMENTS xml INOUT Test segments
@SEQUENCE int INOUT Sequence
@TSLONG bigint INOUT Output parameter indicating the TSLONG value of the record being edited. This is used to manage multi-user concurrency issues when multiple users access the same record.

Definition

Copy


CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDITLOAD_MKTSEGMENTATIONTESTSEGMENT_DRAGDROPINSERT
(
  @ID uniqueidentifier,                                   /* The segment ID. */
  @DATALOADED bit = 0 output,                             /* Returns true if the mailing exists. */
  @TESTSEGMENTS xml = null output,
  @SEQUENCE int = null output,
  @TSLONG bigint = 0 output
)
as
  set nocount on;

  declare @SEGMENTATIONID uniqueidentifier;

  set @DATALOADED = 0;
  set @TSLONG = 0;

  select
    @DATALOADED = 1,
    @SEGMENTATIONID = [SEGMENTATIONID]
  from dbo.[MKTSEGMENTATIONSEGMENT]
  where [ID] = @ID;

  if @DATALOADED = 1
    begin
      with [SEGMENTS_CTE] ([ID], [TSLONG]) as
      (
        select
          [ID],
          [TSLONG]
        from dbo.[MKTSEGMENTATIONSEGMENT]
        where [SEGMENTATIONID] = @SEGMENTATIONID
      )
      select
        @TSLONG = (select max([TSLONG])
                   from (
                     select isnull(max([TSLONG]), 0) as [TSLONG] from [SEGMENTS_CTE]
                     union all
                     select isnull(max([TSLONG]), 0) as [TSLONG] from dbo.[MKTSEGMENTATIONTESTSEGMENT] where [SEGMENTID] in (select [ID] from [SEGMENTS_CTE])
                     union all
                     select isnull(max([TSLONG]), 0) as [TSLONG] from dbo.[MKTMARKETINGPLANBRIEF] where [MARKETINGPLANITEMID] = [MKTSEGMENTATION].[MARKETINGPLANITEMID]
                   ) as [T])
      from dbo.[MKTSEGMENTATION]
      where [ID] = @SEGMENTATIONID;

      --Check if the mailing is currently being activated...

      declare @R int;
      exec @R = dbo.[USP_MKTSEGMENTATION_CHECKACTIVATION] @SEGMENTATIONID;
      if @R <> 0
        begin
          set @DATALOADED = 0;
          return 1;
        end
    end

  return 0;