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 2008 Forums
 Transact-SQL (2008)
 select query how to add sum both fields

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2011-03-16 : 17:20:48
I want to use the following select query, is it possible to show the sum of both fields: (award_amt + amount).

select award_Amt, (select sum(amount) from TAB_CostDet where TaskID = 4 and EstimateType ='Final' and Chgexec = 1) from TAB_Tasks where TaskID=4

Thank you very much for the helpful info.

X002548
Not Just a Number

15586 Posts

Posted - 2011-03-16 : 17:26:12
if you had a real relationship, it would just be a join...

How many rows does that give you?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2011-03-16 : 17:31:03
select inquery can have multiple rows, for that reason using sum(amount), the first field awardAmt just 1 row.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-03-18 : 03:45:47
select award_Amt,amount,award_Amt+amount as total from
(
select award_Amt, (select sum(amount) from TAB_CostDet where TaskID = 4 and EstimateType ='Final' and Chgexec = 1) as amount from TAB_Tasks where TaskID=4
) as t

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -