Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table and need to update the column of that table using some formula. The sample table and data are as below:-

EcodeCountyGroupNameProjectDuration
101NJProject115
101CJProject112
101PKProject310
102NJProject120
102PKProject210


I want to do an update on all duration column.The update will be like this:-
Total duration for ECode 101 is 15+12+10=37 and for Ecode 102 is 20+10=30.The Update will give this as the output:-

EcodeCountyGroupNameProjectDuration
101NJProject1(15*12)/37
101CJProject1(12*12)/37
101PKProject3(10*12)/37
102NJProject1(20*12)/30
102PKProject2(10*12)/30


As in all the duration some calculation is going and the formula will be :-
(Actual Duration*12)/(Sum Of duration for that ECode)

Please provide me the Query in sql.
Posted

1 solution

SQL
UPDATE t1
   SET
      t1.Duration = (t1.Duration*12)/(select SUM(duration) from EmpTable where ECode=t1.ECode)
   FROM
      EmpTable t1,
      EmpTable t2
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900