select cdr_dstcode
from tbl_CDR_Distributors with (nolock)
where cdr_recordId =
and ownerId =
and fsl_tablecode =
select cdr2.cdr_dstcode, cdr2.cdr_recordId, cdr2.cdr_redistAcctFor, cdr2.fsl_dstid, cdr2.cdr_specialAcctType, cdr2.cdr_dstcompanytype, rda.cdr_dstname redistname
from tbl_CDR_Distributors cdr2 with (nolock)
inner join tbl_CDR_Distributors cdr with (nolock)
on cdr.fsl_dstid = cdr2.fsl_dstid
and cdr.ownerId = cdr2.ownerId
and cdr.fsl_tablecode = cdr2.fsl_tablecode
and cdr.cdr_territoryId = cdr2.cdr_territoryId
inner join tbl_CDR_Distributors rda with (nolock)
on rda.cdr_recordId = cdr2.cdr_redistAcctFor
and rda.cdr_dstcompanytype = 'R'
and rda.ownerId = cdr2.ownerId
and rda.fsl_tablecode = cdr2.fsl_tablecode
where cdr2.cdr_dstcompanytype = 'S'
and cdr.cdr_recordId =
and cdr.ownerId =
and cdr.fsl_tablecode =
and cdr.fsl_dstId > 0
order by cdr2.cdr_recordId
select cdr.cdr_recordId
from tbl_CDR_Distributors pcdr with (nolock)
inner join tbl_DST_Distributors dst with (nolock)
on dst.dstid = pcdr.fsl_dstId
inner join tbl_DST_Distributors bdst with (nolock)
on bdst.dstParentCo = dst.dstid
inner join tbl_CDR_Distributors cdr with (nolock)
on cdr.ownerId = pcdr.ownerId
and cdr.fsl_tablecode = pcdr.fsl_tablecode
and cdr.fsl_dstId = bdst.dstid
where pcdr.cdr_recordId =
and pcdr.ownerId =
and pcdr.fsl_tablecode =
select top 1 c.claimId
from tbl_TPM_Claims c with (nolock)
inner join tbl_TPM_ClaimContracts cc with (nolock)
on cc.claimId = c.claimId
and cc.ownerId = c.ownerId
and cc.ownerType = c.ownerType
inner join tbl_TPM_Requests r with (nolock)
on r.requestId = cc.requestId
and r.ownerId = cc.ownerId
and r.ownerType = cc.ownerType
inner join tbl_TPM_RequestTypes rt
on rt.requestTypeId = r.requestTypeId
and rt.primaryPartnerType <> 'CDR'
and rt.ownerId = r.ownerId
and rt.ownerType = r.ownerType
where c.ownerId =
and c.ownerType =
and cc.status like 'APPROVED%'
and (( c.partnerId in ( ) and c.partnerType = 'CDR' )
or exists (
select *
from tbl_MFR_TPF_Detail#_tpfSuffix# with (nolock)
where tpartnerType = 'CDR'
and tpartnerId in ( )
and forecast_status = 'C'
and mfr_id = cc.ownerId
and 'MFR' = cc.ownerType
and rebateContractId = r.requestId
))
select 'DST' as ownerType, fsl_dstId as ownerId
from tbl_CDR_Distributors with (nolock)
where ownerId =
and fsl_tablecode =
and fsl_dstId > 0
and cdr_recordId =