Advertisement
Advertisement
| 04.07.2008 at 07:31AM PDT, ID: 23301465 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: |
/* Retrieve all data for component 8933 */ SELECT a.project_id AS 'Project', a.component_id AS 'Component', LEFT (a.cost_element_id,4) AS 'CE', SUBSTRING (a.cost_element_id,5,1) AS 'CE_End', a.project_ytd_amt AS 'ProjYTD', c.dbs_gl_account AS 'Acct', c.dbs_sub_account AS 'Sub', c.dbs_net_asset_type AS 'NAT', c.dbs_transaction_type AS 'TT', c.dbs_responsibility_center AS 'RC', c.dbs_prod_line AS 'Line', c.dbs_proj_code AS 'Proj', c.dbs_funding_source AS 'Source', c.dbs_tbd AS 'TBD', ISNULL (SUM(c.ldr_amt_1 + c.ldr_amt_2 + c.ldr_amt_3 + c.ldr_amt_4 + c.ldr_amt_5 + c.ldr_amt_6 + c.ldr_amt_7 + c.ldr_amt_8 + c.ldr_amt_9 + c.ldr_amt_10 + c.ldr_amt_11 + c.ldr_amt_12), 99999.99) AS 'LdrYTD' INTO #temp FROM DBSproj.dbo.component_monetary_balance a LEFT OUTER JOIN DBSglep.dbo.ldr_acct_bal c ON a.project_id = c.dbs_proj_code AND a.component_id = c.dbs_funding_source AND LEFT(a.cost_element_id,4) = c.dbs_gl_account WHERE a.curr_type = 'P' AND a.fiscal_year = '2008' AND a.amt_class_type = 'ACTUAL' AND a.component_id = '8933' AND c.curr_type = 'B1' AND c.amt_class_type = 'ACTUAL' AND c.processing_yr = '2008' GROUP BY a.project_id,a.component_id,a.cost_element_id,a.project_ytd_amt,c.dbs_proj_code,c.dbs_funding_source, c.dbs_gl_account,c.dbs_sub_account,c.dbs_net_asset_type,c.dbs_transaction_type, c.dbs_responsibility_center,c.dbs_prod_line,c.dbs_proj_code,c.dbs_funding_source,c.dbs_tbd ORDER BY a.project_id /* Strip cost element 5th character, sum up amt by Project, Component, CE, place in new temp table */ SELECT Project,Component,CE,SUM(ProjYTD)AS 'SUMProjYTD' INTO #projtemp FROM #temp GROUP BY Project, Component,CE /* Place Ledger accounts and amounts in new temp table */ SELECT DISTINCT Acct,Sub,NAT,TT,RC,Line,Proj,Source,TBD,LdrYTD INTO #ldrtemp FROM #temp GROUP BY Acct, Sub,NAT,TT,RC,Line,Proj,Source,TBD,LdrYTD /* Compare the two new table table amounts for variances */ SELECT a.*,b.*,ISNULL((a.SUMProjYTD - b.LdrYTD),99999.99) AS Variance FROM #projtemp a INNER JOIN #ldrtemp b ON a.Project = b.Proj AND a.Component = b.Source AND a.CE = b.Acct ORDER BY a.Project /* Drop temp tables */ DROP TABLE #temp DROP TABLE #projtemp DROP TABLE #ldrtemp |