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 |
|
cat_jesus
Aged Yak Warrior
547 Posts |
Posted - 2001-11-02 : 12:37:24
|
| I have a need to update a date in a table with the date of the record that is just lower than it's date. Take the following table.customer varchar(10),account_date datetime,group_id int,account_date_prev datetime -- previous dateThere are multiple occurences of customer, but the unique key is customer and account_date but I also need to group by group_id.I wrote the following update but it is way to slow, there has to be a better way.update custset account_date_prev = sl.mxfrom (select P2.customer, P2.group_id, max(P2.account_date) as mxfrom cust Pjoin cust P2 on P.customer = P2.customer and P.group_id = P2.group_id and P.account_date > P2.account_dategroup by P2.customer, P2.group_id) as slI've got to be missing something really basic but I just can't seem to see it.Anyone?Catedit: was trying to update the wrong column in the set.Edited by - cat_jesus on 11/02/2001 13:08:52 |
|
|
|
|
|