|
flamblaster
Constraint Violating Yak Guru
384 Posts |
Posted - 2012-06-27 : 23:57:33
|
| Ok, so I'm just guessing this is what you want from what you posted. Any time you're doing an update, you will really need to check to make sure this is absolutely what you want to do...so I'd test it before making the change:declare @TBL_INF table (pid int, rate int)declare @TBL_DETAIL table (pid int, rate int, Sdate date)insert into @TBL_INF (pid, rate)values (1, 15),(2, 16),(3, 20)insert into @TBL_DETAIL (pid, rate, Sdate)values(1, 15, '30-MAY-2012'),(1, 18, '1-JUN-2012'),(1, 19, '5-JUN-2012'), (1, 22, '18-JUN-2012'), (2, 16, '30-MAY-2012'), (2, 18, '1-JUN-2012'), (2, 19, '20-JUN-2012'), (3, 20, '05-JUN-2012'),(3, 24, '06-JUN-2012') --Check data prior to the updateselect TI.pid, TI.rate, TD.rate, TD.SDatefrom @TBL_INF TIjoin @TBL_DETAIL TD on TD.pid=TI.pid--Set your Check Datedeclare @CheckDate dateset @CheckDate='05-JUN-2012'--Update TBL_INF based on the date checkupdate @TBL_INFset rate=D.ratefrom @TBL_INF Tjoin @TBL_DETAIL D on D.pid=T.pidwhere d.Sdate=@CheckDate--Check data after doing the updateselect TI.pid, TI.rate, TD.rate, TD.SDatefrom @TBL_INF TIjoin @TBL_DETAIL TD on TD.pid=TI.pid |
 |
|