Solved

Budget and Cost Report

Posted on 2012-03-19
1
283 Views
Last Modified: 2012-03-25
I am currently working on the above report.  The monthly budgets are contained in one table, the costs in another.  If work from the budgets table to costs I can see all costs against a cost code that has a budget, but if costs are incurred against a cost code that doesn't have a budget this will be missed.  I could work the other way from costs to budgets but the report wouldn't show costs codes that had a budget but where no costs had been incurred.

Please can someone advise on the best approach?
0
Comment
Question by:Damozz
1 Comment
 
LVL 42

Accepted Solution

by:
dqmq earned 500 total points
ID: 37739960
Use an outer join to get all costs with their budgets (or lack thereof)

Select...
from Costs c left join budgets b on c.costcode = b.costcode

go the other way to get all budgets with their costs (or lack thereof)
Select...
from Costs c right join budgets b on c.costcode = b.costcode

Most reports are best developed with one of the above forms.  To see it both ways, probably best to use two reports or two sub-reports.


You can also use full outer join  to get all budgets and all costs at one time, but it gets a little tricky developing a meaningful report when sometimes the budgets are missing and sometimes the costs are missing.

Select...
from Costs c full outer join budgets b on c.costcode = b.costcode
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sql help 8 55
SQL SELECT query help 7 34
always on switch back after failover 2 32
optimize stored procedure 6 24
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question