select * from qmd_data where CountCasesY = 'Y' select distinct c.contractid, r.requestId from tbl_TPM_Contracts c with (nolock) inner join tbl_TPM_Requests r with (nolock) on r.ownerId = c.ownerId and r.ownerType = c.ownerType and r.contractId = c.contractId where c.ownerid = 1 and c.ownerType = 'MFR' and c.assignedContractNbr = and r.volumeGenerator = 'N' update c set flaggedForRecalc = 'Y', flaggedForRecalcTime = getDate() from tbl_TPM_Contracts c where c.ownerid = 1 and c.ownerType = 'MFR' and c.contractId = and flaggedForRecalc = 'N' update r set volumeGenerator = 'Y' from tbl_TPM_Requests r where r.ownerid = 1 and r.ownerType = 'MFR' and r.contractId = and r.volumeGenerator = 'N'