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 |
shakilhyd
Starting Member
16 Posts |
Posted - 2008-07-15 : 09:40:49
|
SELECT empid,type,volfrom curben where type in ('cash','hsaf') and empid in ('2013','5227')empid type vol ---------- ---- ------------------------ 2013 CASH 686.0000000000002013 HSAF 445.0000000000005227 CASH .0000000000005227 HSAF 1174.000000000000Now I want update the volume type-HSAF with volume of CASH+HSAFI need following output after updating. Remember that CASH-volume is zero of empid-5227What will be the update script. Please helpempid type vol ---------- ---- ------------------------ 2013 CASH 686.0000000000002013 HSAF 1131.000000000000 --686+445=11315227 CASH .0000000000005227 HSAF 1174.000000000000 --0+1174=1174 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-15 : 09:55:34
|
You should do Running Totals in your front end applicationSelect empid,type,(select sum(vol) from table where empid=t.empid and type<=t.type) as vol from table t1where type in ('cash','hsaf') and empid in ('2013','5227')MadhivananFailing to plan is Planning to fail |
 |
|
shakilhyd
Starting Member
16 Posts |
Posted - 2008-07-15 : 10:35:11
|
Hi,Its wrong. Actually I want to update field such asUpdate Curbenset vol=HSAFvolume+CASHvolumewhere cash's volume>0Can you please help in update script.Thanks. quote: Originally posted by madhivanan You should do Running Totals in your front end applicationSelect empid,type,(select sum(vol) from table where empid=t.empid and type<=t.type) as vol from table t1where type in ('cash','hsaf') and empid in ('2013','5227')MadhivananFailing to plan is Planning to fail
|
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-15 : 11:01:01
|
I advise you to do this in front end application. If there is no optionUpdate t1set t1.vol=t2.volfrom table t1 inner join(Select empid,type,(select sum(vol) from table where empid=t.empid and type<=t.type) as vol from table twhere type in ('cash','hsaf') and empid in ('2013','5227')) as t2 on t1.empid=t2.empid and t1.type=t2.typeMadhivananFailing to plan is Planning to fail |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-15 : 13:56:54
|
quote: Originally posted by shakilhyd SELECT empid,type,volfrom curben where type in ('cash','hsaf') and empid in ('2013','5227')empid type vol ---------- ---- ------------------------ 2013 CASH 686.0000000000002013 HSAF 445.0000000000005227 CASH .0000000000005227 HSAF 1174.000000000000Now I want update the volume type-HSAF with volume of CASH+HSAFI need following output after updating. Remember that CASH-volume is zero of empid-5227What will be the update script. Please helpempid type vol ---------- ---- ------------------------ 2013 CASH 686.0000000000002013 HSAF 1131.000000000000 --686+445=11315227 CASH .0000000000005227 HSAF 1174.000000000000 --0+1174=1174
will you be having only 1 CASH & HSAF records per empid then you can useUPDATE tSET t.vol=t.vol + t1.volFROm YoutTable tINNER JOIN YourTable t1ON t1.empid =t.empidAND t1.type='CASH'WHERE t.type='HSAF' if this is not your scenario please explain how you want the update to happen?simply from all CASH records of empid or sum of all cash records that happen before current HSAF (you should have a date field for that) |
 |
|
|
|
|
|
|