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
 Correlated subquery

Author  Topic 

sent_sara
Constraint Violating Yak Guru

377 Posts

Posted - 2008-09-23 : 04:40:05
Table name:onsite_plstatement_tmp
sno name amt
1 AA 100.00
2 BB 100.00
3 cc 200.00
4 DD 300.00
5 Total null

I need to update the 5th Total column 700.00

my try is,can any one correct the below query:
update A
set A.amt=sum(A.amt)
from onsite_plstatement_tmp A
where guid=@guid and sno between 1 and 4
Note: for the sno=5 the total value should be 700.00

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-23 : 04:49:53
[code]update onsite_plstatement_tmp
set amt=(select sum(amt)
from onsite_plstatement_tmp
where guid=@guid and sno between 1 and 4)
where sno=5[/code]
Go to Top of Page
   

- Advertisement -