utl_pushClosedCallForwardToFollupUp.cfm
| struct |
| DATASOURCE |
fslibrary_rpc
|
| DEBUG |
true
|
| INTERACTIONID |
9816527
|
| OWNERID |
228
|
| OWNERTYPE |
BRO
|
declare @ownerId int = 228 ;
declare @ownerType varchar(3) = 'BRO' ;
declare @interactionId int = 9816527 ;
with
closedCall as (
select i.ownerId, i.ownerType, i.interactionId, i.partnerId, i.partnerType, i.updateDate, coalesce( isd.saleSubjectType, '' ) saleSubjectType, coalesce( isd.saleSubjectId, 0 ) saleSubjectId,
isd.saleQty, isd.saleDurationUnit, isd.saleDurationAmt, isd.annualCaseAmt, isd.annualWeightAmt, isd.annualDollarAmt, isd.availableDate, isd.stageId, isd.typeCode, coalesce( isd.cdrDistributorId, 0 ) as cdrDistributorId,
i.dispositionUserId
from tbl_CRM_interactions i with (nolock)
inner join tbl_CRM_interactionSaleDetails isd with (nolock)
on isd.ownerId = i.ownerId
and isd.ownertype = i.ownerType
and isd.interactionId = i.interactionId
where i.disposition != '?'
and isd.disposition = 'FU'
and i.ownerId = @ownerId
and i.ownerType = @ownerType
and i.interactionId = @interactionId
),
openCall as (
select i.interactionDate, i.ownerId, i.ownerType, i.interactionId, i.partnerId, i.partnerType, i.updateDate, i.dispositionUserId,
isd.interactionDetailId, coalesce( isd.saleSubjectType, '' ) saleSubjectType, coalesce( isd.saleSubjectId, 0 ) saleSubjectId,
isd.saleQty, isd.saleDurationUnit, isd.saleDurationAmt, isd.annualCaseAmt, isd.annualWeightAmt, isd.annualDollarAmt, isd.availableDate, isd.stageId, isd.typeCode, coalesce( isd.cdrDistributorId, 0 ) as cdrDistributorId,
ci.saleQty closedCallSaleQty, ci.saleDurationUnit closedCallSaleDurationUnit, ci.saleDurationAmt closedCallSaleDurationAmt, ci.annualCaseAmt closedCallAnnualCaseAmt, ci.annualWeightAmt closedCallAnnualWeightAmt, ci.annualDollarAmt closedCallAnnualDollarAmt, ci.availableDate closedCallAvailableDate, ci.stageId closedCallStageId, ci.typeCode as closedCallTypeCode, ci.cdrDistributorId as closedCallCdrDistributorId,
ci.dispositionUserId as closedCallDispositionUserId
from tbl_CRM_interactions i with (nolock)
inner join tbl_CRM_interactionSaleDetails isd with (nolock)
on isd.ownerId = i.ownerId
and isd.ownertype = i.ownerType
and isd.interactionId = i.interactionId
inner join closedCall ci with (nolock)
on ci.ownerId = i.ownerId
and ci.ownerType = i.ownerType
and ci.partnerId = i.partnerId
and ci.partnerType = i.partnerType
and ci.saleSubjectId = coalesce( isd.saleSubjectId, 0 )
and ci.saleSubjectType = coalesce( isd.saleSubjectType, '' )
where i.disposition = '?'
and isd.disposition = 'FU'
and i.ownerId = @ownerId
and i.ownerType = @ownerType
and i.interactionId != @interactionId
and isd.updateDate < ci.updateDate
),
callChanges as (
select *
from openCall o
where o.saleQty != o.closedCallSaleQty
or o.saleDurationUnit != o.closedCallSaleDurationUnit
or coalesce( o.saleDurationAmt, 0 ) != coalesce( o.closedCallSaleDurationAmt, 0 )
or o.annualCaseAmt != o.closedCallAnnualCaseAmt
or o.annualWeightAmt != o.closedCallAnnualWeightAmt
or o.annualDollarAmt != o.closedCallAnnualDollarAmt
or o.availableDate != o.closedCallAvailableDate
or o.stageId != o.closedCallStageId
or o.typeCode != o.closedCallTypeCode
or o.cdrDistributorId != o.closedCallCdrDistributorId
)
select interactionId, interactionDate, partnerId, partnerType, interactionDetailId, saleSubjectType, saleSubjectId, dispositionUserId,
saleQty, saleDurationUnit, saleDurationAmt, annualCaseAmt, annualWeightAmt, annualDollarAmt, availableDate, stageId, typeCode, cdrDistributorId,
closedCallSaleQty, closedCallSaleDurationUnit, closedCallSaleDurationAmt, closedCallAnnualCaseAmt, closedCallAnnualWeightAmt, closedCallAnnualDollarAmt, closedCallAvailableDate, closedCallStageId, closedCallTypeCode, closedCallCdrDistributorId,
closedCallDispositionUserId
from callChanges
order by interactionId
| query |
| RESULTSET |
| query |
| |
ANNUALCASEAMT |
ANNUALDOLLARAMT |
ANNUALWEIGHTAMT |
AVAILABLEDATE |
CDRDISTRIBUTORID |
CLOSEDCALLANNUALCASEAMT |
CLOSEDCALLANNUALDOLLARAMT |
CLOSEDCALLANNUALWEIGHTAMT |
CLOSEDCALLAVAILABLEDATE |
CLOSEDCALLCDRDISTRIBUTORID |
CLOSEDCALLDISPOSITIONUSERID |
CLOSEDCALLSALEDURATIONAMT |
CLOSEDCALLSALEDURATIONUNIT |
CLOSEDCALLSALEQTY |
CLOSEDCALLSTAGEID |
CLOSEDCALLTYPECODE |
DISPOSITIONUSERID |
INTERACTIONDATE |
INTERACTIONDETAILID |
INTERACTIONID |
PARTNERID |
PARTNERTYPE |
SALEDURATIONAMT |
SALEDURATIONUNIT |
SALEQTY |
SALESUBJECTID |
SALESUBJECTTYPE |
STAGEID |
TYPECODE |
|
| CACHED |
false |
| EXECUTIONTIME |
48 |
| SQL |
declare @ownerId int = 228 ;
declare @ownerType varchar(3) = 'BRO' ;
declare @interactionId int = 9816527 ;
with
closedCall as (
select i.ownerId, i.ownerType, i.interactionId, i.partnerId, i.partnerType, i.updateDate, coalesce( isd.saleSubjectType, '' ) saleSubjectType, coalesce( isd.saleSubjectId, 0 ) saleSubjectId,
isd.saleQty, isd.saleDurationUnit, isd.saleDurationAmt, isd.annualCaseAmt, isd.annualWeightAmt, isd.annualDollarAmt, isd.availableDate, isd.stageId, isd.typeCode, coalesce( isd.cdrDistributorId, 0 ) as cdrDistributorId,
i.dispositionUserId
from tbl_CRM_interactions i with (nolock)
inner join tbl_CRM_interactionSaleDetails isd with (nolock)
on isd.ownerId = i.ownerId
and isd.ownertype = i.ownerType
and isd.interactionId = i.interactionId
where i.disposition != '?'
and isd.disposition = 'FU'
and i.ownerId = @ownerId
and i.ownerType = @ownerType
and i.interactionId = @interactionId
),
openCall as (
select i.interactionDate, i.ownerId, i.ownerType, i.interactionId, i.partnerId, i.partnerType, i.updateDate, i.dispositionUserId,
isd.interactionDetailId, coalesce( isd.saleSubjectType, '' ) saleSubjectType, coalesce( isd.saleSubjectId, 0 ) saleSubjectId,
isd.saleQty, isd.saleDurationUnit, isd.saleDurationAmt, isd.annualCaseAmt, isd.annualWeightAmt, isd.annualDollarAmt, isd.availableDate, isd.stageId, isd.typeCode, coalesce( isd.cdrDistributorId, 0 ) as cdrDistributorId,
ci.saleQty closedCallSaleQty, ci.saleDurationUnit closedCallSaleDurationUnit, ci.saleDurationAmt closedCallSaleDurationAmt, ci.annualCaseAmt closedCallAnnualCaseAmt, ci.annualWeightAmt closedCallAnnualWeightAmt, ci.annualDollarAmt closedCallAnnualDollarAmt, ci.availableDate closedCallAvailableDate, ci.stageId closedCallStageId, ci.typeCode as closedCallTypeCode, ci.cdrDistributorId as closedCallCdrDistributorId,
ci.dispositionUserId as closedCallDispositionUserId
from tbl_CRM_interactions i with (nolock)
inner join tbl_CRM_interactionSaleDetails isd with (nolock)
on isd.ownerId = i.ownerId
and isd.ownertype = i.ownerType
and isd.interactionId = i.interactionId
inner join closedCall ci with (nolock)
on ci.ownerId = i.ownerId
and ci.ownerType = i.ownerType
and ci.partnerId = i.partnerId
and ci.partnerType = i.partnerType
and ci.saleSubjectId = coalesce( isd.saleSubjectId, 0 )
and ci.saleSubjectType = coalesce( isd.saleSubjectType, '' )
where i.disposition = '?'
and isd.disposition = 'FU'
and i.ownerId = @ownerId
and i.ownerType = @ownerType
and i.interactionId != @interactionId
and isd.updateDate < ci.updateDate
),
callChanges as (
select *
from openCall o
where o.saleQty != o.closedCallSaleQty
or o.saleDurationUnit != o.closedCallSaleDurationUnit
or coalesce( o.saleDurationAmt, 0 ) != coalesce( o.closedCallSaleDurationAmt, 0 )
or o.annualCaseAmt != o.closedCallAnnualCaseAmt
or o.annualWeightAmt != o.closedCallAnnualWeightAmt
or o.annualDollarAmt != o.closedCallAnnualDollarAmt
or o.availableDate != o.closedCallAvailableDate
or o.stageId != o.closedCallStageId
or o.typeCode != o.closedCallTypeCode
or o.cdrDistributorId != o.closedCallCdrDistributorId
)
select interactionId, interactionDate, partnerId, partnerType, interactionDetailId, saleSubjectType, saleSubjectId, dispositionUserId,
saleQty, saleDurationUnit, saleDurationAmt, annualCaseAmt, annualWeightAmt, annualDollarAmt, availableDate, stageId, typeCode, cdrDistributorId,
closedCallSaleQty, closedCallSaleDurationUnit, closedCallSaleDurationAmt, closedCallAnnualCaseAmt, closedCallAnnualWeightAmt, closedCallAnnualDollarAmt, closedCallAvailableDate, closedCallStageId, closedCallTypeCode, closedCallCdrDistributorId,
closedCallDispositionUserId
from callChanges
order by interactionId |