select cc.ownerId, cc.ownerType, cc.claimId, ct.assignedContractNbr, cc.contractNbr, ct.contractId, cc.reconciled from tbl_TPM_ClaimContracts cc with (nolock) 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_Contracts ct with (nolock) on ct.contractId = r.contractId and ct.ownerId = r.ownerId and ct.ownerType = r.ownerType where ct.ownerId = and ct.ownerType = and ct.partnerId = and ct.partnerType = and ct.assignedContractNbr = and r.volumeGenerator = order by cc.claimId update tbl_TPM_Contracts set flaggedForRecalc = 'Y', flaggedForRecalcTime = getDate() where flaggedForRecalc = 'N' and ownerId = and ownerType = and contractId =