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.
| Author |
Topic |
|
pnpsql
Posting Yak Master
246 Posts |
Posted - 2011-10-12 : 07:14:09
|
| i have a table like : id name amount type 1 a 120 x 2 a 120 x 3 c 120.41 y i need to deduct amount equals to amount of a from name c. i need to use only quey not t sql block pls help....challenge everything |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2011-10-12 : 07:41:37
|
| Not sure what you wantupdate tblset amount = amount - (select sum(amount) from tbl where name = a)where name = c==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-10-12 : 08:12:24
|
| [code]update tset t.amount = t.amount - b.tot from tbl tcross apply (select sum(amount) as tot from tbl where name < t.name) b[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|