SELECT
SUM(paymentAmt)
INTO
:count
FROM
(
SELECT
SUM(InstructionLineItem.amount) AS paymentAmt
FROM
CaseDecisionFinancialComp,
CaseDecisionObjective,
InstructionLineItem
WHERE CaseDecisionFinancialComp.caseDecisionObjectiveID = CaseDecisionObjective.caseDecisionObjectiveID
AND InstructionLineItem.financialCompID = CaseDecisionFinancialComp.financialCompID
AND CaseDecisionObjective.overflowInd = :overflowInd
AND CaseDecisionObjective.relatedReference IN
(
SELECT
CAST(ServiceInvoiceLineItem.serviceInvoiceLineItemID AS CHAR(20))
FROM
ServiceInvoiceLineItem,
ProviderOffering,
ServiceOffering
WHERE ProviderOffering.providerOfferingID = :resourceID
AND ProviderOffering.serviceOfferingID = ServiceOffering.serviceOfferingID
AND ServiceInvoiceLineItem.serviceID = ServiceOffering.serviceOfferingID
)
AND InstructionLineItem.instructionLineItemType = :siliInstructionLineItemType
AND InstructionLineItem.instructLineItemCategory = :instructLineItemCategory
AND InstructionLineItem.statusCode = :statusCode
UNION ALL
SELECT
SUM(InstructionLineItem.amount) AS paymentAmt
FROM
CaseDecisionFinancialComp,
CaseDecisionObjective,
InstructionLineItem
WHERE CaseDecisionFinancialComp.caseDecisionObjectiveID = CaseDecisionObjective.caseDecisionObjectiveID
AND InstructionLineItem.financialCompID = CaseDecisionFinancialComp.financialCompID
AND CaseDecisionObjective.overflowInd = :overflowInd
AND CaseDecisionObjective.relatedReference IN
(
SELECT
CAST(ContractVersion.contractVersionID AS CHAR(20))
FROM
ContractVersion,
ContractPOLink,
FlatRateContract
WHERE ContractPOLink.providerOfferingID = :resourceID
AND ContractPOLink.contractVersionID = ContractVersion.contractVersionID
AND ContractVersion.contractType = :contractType
AND ContractVersion.status = :contractStatus
AND FlatRateContract.contractVersionID = ContractVersion.contractVersionID
)
AND InstructionLineItem.instructionLineItemType = :frContractInstructionLineItemType
AND InstructionLineItem.instructLineItemCategory = :instructLineItemCategory
AND InstructionLineItem.statusCode = :statusCode
UNION ALL
SELECT
SUM(InstructionLineItem.amount) AS paymentAmt
FROM
CaseDecisionFinancialComp,
CaseDecisionObjective,
InstructionLineItem
WHERE CaseDecisionFinancialComp.caseDecisionObjectiveID = CaseDecisionObjective.caseDecisionObjectiveID
AND InstructionLineItem.financialCompID = CaseDecisionFinancialComp.financialCompID
AND CaseDecisionObjective.overflowInd = :overflowInd
AND CaseDecisionObjective.relatedReference IN
(
SELECT
CAST(ProviderRosterLineItem.providerRosterLineItemID AS CHAR(20))
FROM
ProviderRosterLineItem,
RosterLineItem,
Roster
WHERE Roster.serviceID = :resourceID
AND Roster.rosterID = RosterLineItem.rosterID
AND RosterLineItem.rosterLineItemID = ProviderRosterLineItem.rosterLineItemID
)
AND InstructionLineItem.instructionLineItemType = :rosterInstructionLineItemType
AND InstructionLineItem.instructLineItemCategory = :instructLineItemCategory
AND InstructionLineItem.statusCode = :statusCode
UNION ALL
SELECT
SUM(InstructionLineItem.amount) AS paymentAmt
FROM
CaseDecisionFinancialComp,
CaseDecisionObjective,
InstructionLineItem
WHERE CaseDecisionFinancialComp.caseDecisionObjectiveID = CaseDecisionObjective.caseDecisionObjectiveID
AND InstructionLineItem.financialCompID = CaseDecisionFinancialComp.financialCompID
AND CaseDecisionObjective.overflowInd = :overflowInd
AND CaseDecisionObjective.relatedReference IN
(
SELECT
CAST(Placement.placementID AS CHAR(20))
FROM
Placement,
ProviderOffering,
ServiceOffering
WHERE Placement.providerOfferingID = :resourceID
AND Placement.recordStatus = :recordStatus
AND ProviderOffering.serviceOfferingID = ServiceOffering.serviceOfferingID
AND ServiceOffering.placementPmtInd = :placementPmtInd
)
AND InstructionLineItem.instructionLineItemType = :placementInstructionLineItemType
AND InstructionLineItem.instructLineItemCategory = :instructLineItemCategory
AND InstructionLineItem.statusCode = :statusCode
) InstructionLineItem
|