Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Show all records from one table for EACH record in

Author  Topic 

dabooj
Starting Member

7 Posts

Posted - 2009-04-16 : 07:45:22
Hi,

I have a funding table which has records listed per year for a business case. BUsiness case is the parent table & the funding table is the child table with a one-to-many relationship.
Each business case can therefore have one funding record listed which shows 1 year or it can have many funding records for a number of years. The years will fall into 2007-2012 as this is the length of business case timeline.

EG, Business case 1 has funding record £5000 for 2007.
Business case 2 has funding records £3000 for 2009, £5000 for 2010, £7000 for 2011.

For a main report that i have, i have to list the year data grouped by the year so i have totals for each year BUT i'm struggling to figure out how to do this because i need to list all possible years in a matrix. Further more, this needs to be grouped by the project lead field so it lists all possible years of funding per person (each project lead can be a lead for 1 or more cases).

EG,
Joe Bloggs (project lead) (lead of 3 business cases grouped in the following totals)
year - total (£)
2007 - £10000
2008 - NULL
2009 - £20000
2010 - £15000
2011 - NULL
2012 - £4000

Jim Bob (project lead) (lead of 1 business case grouped in the following totals)
year - total (£)
2007 - NULL
2008 - NULL
2009 - £200
2010 - NULL
2011 - NULL
2012 - £3500

I created a static table to hold the years as records in the table. I then tried to link this table with my funding table as a right outer join to show all records from the year table but this shows the related years and then the additional years as single entiries. I need to seperate the records so ALL years are listed for each project lead & the amounts are summed by year.

I know this is a bit confusing so i hope i have explained this well. Can anyone help with this one?

Regards,

Shuja

Shuja Ahmad
Systems Developer

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2009-04-16 : 07:50:53
Hi. Follow the first link in my signature, then restate your question following the suggestions in the link. It will make your question MUCH easier to understand AND answer.

Now that I have said this, "Entry Level DBA"™ Peso will probably answer it instantly.

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL or How to sell Used Cars
For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

aprichard
Yak Posting Veteran

62 Posts

Posted - 2009-04-16 : 08:02:01
Can you post sample data and proposed output
Go to Top of Page

dabooj
Starting Member

7 Posts

Posted - 2009-04-16 : 12:09:35
I've managed to find a possible solution using cross joins. See the following thread for more detail:
http://www.dbforums.com/microsoft-sql-server/1641161-show-all-records-one-table-each-record-another-table.html

Shuja Ahmad
Systems Developer
Go to Top of Page
   

- Advertisement -