If you work with VI contract costing chances are you need to run comaprisons of actual costs against initial and current estimates. This query will give you the initial costs and revenue for each contract grouped by expense code and expense group. If you look at the comment section you can change MIN to MAX to get the latest estimate.
SELECT ced.contract_code, ccg.expense_code, ccg.expense_group, ced.cost, ced.revenue FROM scheme.cfercdm AS ccg WITH (NOLOCK) INNER JOIN ( SELECT esta.contract_code, esta.expense_code, estb.version, SUM(esta.cost) AS cost, SUM(esta.revenue) AS revenue FROM scheme.coestdtm AS esta WITH (NOLOCK) INNER JOIN ( SELECT contract_code, expense_code, MIN(estimate_vers) AS version FROM scheme.coestdtm WITH (NOLOCK) GROUP BY contract_code, expense_code) AS estb ON esta.contract_code + esta.expense_code + esta.estimate_vers = estb.contract_code + estb.expense_code + estb.version GROUP BY esta.contract_code, esta.expense_code, estb.version) AS ced ON ccg.expense_code = ced.expense_code



















No Comment Received
Sorry the comment area are closed for non registered users