USP_DATAFORMTEMPLATE_EDITLOAD_EXTENDEDRELATIONSHIP_BOLINKORGTOCONSTIT

The load procedure used by the edit dataform template "Extended Relationship Business Ownership Link Organization To Constituent Edit Data 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.
@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.
@CONSTITUENTID uniqueidentifier INOUT Company
@COMPANY nvarchar(100) INOUT Company name
@LINE1 nvarchar(150) INOUT Line 1
@CITY nvarchar(30) INOUT City
@STATEID uniqueidentifier INOUT State ID
@ZIP nvarchar(10) INOUT Zip
@PHONE nvarchar(20) INOUT Phone
@EMPLOYEES_TOTAL int INOUT Total employees
@INFOSOURCECODEID uniqueidentifier INOUT Info source code ID

Definition

Copy


CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDITLOAD_EXTENDEDRELATIONSHIP_BOLINKORGTOCONSTIT(
    @ID uniqueidentifier,
    @DATALOADED bit = 0 output,
    @TSLONG bigint = 0 output,
    @CONSTITUENTID uniqueidentifier = null output,
    @COMPANY nvarchar(100) = null output,
    @LINE1 nvarchar(150) = null output,
    @CITY nvarchar(30) = null output,
    @STATEID uniqueidentifier = null output,
    @ZIP nvarchar(10) = null output,
    @PHONE nvarchar(20) = null output,
    @EMPLOYEES_TOTAL int = null output,
    @INFOSOURCECODEID uniqueidentifier = null output
)
as

    set nocount on;

    declare @CHANGEAGENTID uniqueidentifier
    exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output

    declare @CURRENTDATE datetime
    set @CURRENTDATE = getdate()

    declare @DEFAULTCOUNTRYID uniqueidentifier;
    exec @DEFAULTCOUNTRYID = dbo.UFN_COUNTRY_GETDEFAULT;

    -- be sure to set these, in case the select returns no rows

    set @DATALOADED = 0
    set @TSLONG = 0

    -- populate the output parameters, which correspond to fields on the form.  Note that

    -- we set @DATALOADED = 1 to indicate that the load was successful.  Otherwise, the system

    -- will display a "no data loaded" message.  Also note that we fetch the TSLONG so that concurrency

    -- can be considered.

    select
        @DATALOADED = 1,
        @TSLONG = BO.TSLONG,
        @CONSTITUENTID = BO.CONSTITUENTID,
        @COMPANY = WP.COMPANY,
        @LINE1 = WP.LINE1,
        @CITY = WP.CITY,
        @STATEID = (select top(1) ID from dbo.STATE where COUNTRYID = @DEFAULTCOUNTRYID and (DESCRIPTION = WP.STATE or ABBREVIATION = WP.STATE)),
        @ZIP = WP.ZIP,
        @EMPLOYEES_TOTAL = WP.EMPLOYEES_TOTAL,
        @PHONE = WP.PHONE
    from 
        dbo.WPBUSINESSOWNERSHIP WP
    left join
        dbo.WPRELATIONSHIP_BO BO on WP.WPRELATIONSHIP_BO_ID = BO.ID
    where WP.ID = @ID

    select @INFOSOURCECODEID = ID from dbo.INFOSOURCECODE where DESCRIPTION = 'D&B'
    if @INFOSOURCECODEID is null begin
        insert into dbo.INFOSOURCECODE
        (
            DESCRIPTION,
            ADDEDBYID,
            CHANGEDBYID,
            DATEADDED,
            DATECHANGED
        )
        values
        (
            'D&B',
            @CHANGEAGENTID,
            @CHANGEAGENTID,
            @CURRENTDATE,
            @CURRENTDATE
        )
        select @INFOSOURCECODEID = ID from dbo.INFOSOURCECODE where DESCRIPTION = 'D&B'
    end

    return 0;