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
 General SQL Server Forums
 New to SQL Server Programming
 Adding values

Author  Topic 

godspeedba
Yak Posting Veteran

90 Posts

Posted - 2010-09-17 : 05:00:13
Good day friends,

Hope you are all well.

I am having trouble at attempting to create an output from 2 tables.

Basically I have 2 tables -
TB_Project - contains Project_ID, Project_name
TB_Stage - Contains Stage_id, Project_ID, Stage_Cost(money type)

1 Project has multiple stages

I was trying to join the details into a temptable where I would get the project name and the project cost(all of the stage costs added together)

SELECT Project_id, Project_name, (....)
from tb_projects

but what do I put in the brackets that can add the stage_costs together.

Any assistance would be greatly received.

Thank you for your time.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-09-17 : 05:40:45
select
p.Project_ID,
p.Project_name,
dt.Project_Cost
from TB_Project as p
join
(
select Project_ID, sum(Stage_Cost) as Project_Cost
from TB_Stage
group by Project_ID
) as dt
on dt.Project_ID = p.Project_ID



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-09-17 : 05:55:07
OR

select
p.Project_ID,
p.Project_name,
SUM(s.Project_Cost)over() TotalCost
from TB_Project as p
join TB_Stage s
on s.Project_ID = p.Project_ID



Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless.

PBUH
Go to Top of Page

godspeedba
Yak Posting Veteran

90 Posts

Posted - 2010-09-17 : 06:01:33
Thank you very much guys :)
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-09-17 : 06:07:50
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -