• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

Update table

Hi,

I have this table with these field.
ProjectID    CrAmount     DbAmount      Diff
1987              5                    2    
1987              4                    7  
6931              6                    2
1987              9                    3
6931              5                    4
4511              9                    2  

what I want is to make the data like this table
order by projectId
sum CrAmount      Sum DrAmount
and put the difference in the difference column.

this is the output that I want.
ProjectID    CrAmount     DbAmount      Diff
1987             18                  12               6
6931              3                    6                -3
4511              9                    2                 7


         
0
lulu50
Asked:
lulu50
  • 4
  • 3
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
this should do:
select ProjectId, sum(crAmount), sum(ddamount), sum(diff)
  from yourtable
 group by projetid

Open in new window

0
 
lulu50Author Commented:
I have to do an update to the temp table
0
 
lulu50Author Commented:
the diff is the sum(cramount) - sum(ddamount) as diff
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
sorry:
select ProjectId, sum(crAmount), sum(ddamount), sum(crAmount) - sum(ddamount)
  from yourtable
 group by projetid

Open in new window

0
 
lulu50Author Commented:
How can I clear data from a #tempTable
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
truncate table #tempTable

or

drop and recreate it
0
 
lulu50Author Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now