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 |
sqlserverdeveloper
Posting Yak Master
243 Posts |
Posted - 2008-06-25 : 13:31:05
|
The follow is the data I have in a single table:createdate IDcolumn Custnumber12/1/2005 2 1005/1/2007 1 1005/29/2007 2 1005/30/2007 3 1006/1/12007 4 1006/28/2007 5 1002/1/2006 2 2006/1/20007 1 2006/5/2007 2 2006/7/2007 3 2002/5/2005 4 3006/10/2008 1 300For the above data, if the first row's createdate is less than second row's createdate for the same custnumber 100,then the IDcolumn of the first row should be updated to 1, and accordingly if the second row's createdate is less than3rd row, then second row's IDcolumn should be 2 etc., the following is the output I am expecting:createdate IDcolumn Custnumber12/1/2005 1 1005/1/2007 2 1005/29/2007 3 1005/30/2007 4 1006/1/12007 5 1006/28/2007 6 1002/1/2006 1 2006/1/20007 2 2006/5/2007 3 2006/7/2007 4 2002/5/2005 1 3006/10/2008 2 300Any ideas are greatly appreciated, Thanks!! |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-25 : 13:34:43
|
[code]UPDATE tSET t.IDColumn=(SELECT COUNT(*) FROM YourTable WHERE CustNumber=t.CustNumberAND createdate <t.createdate) +1FROM YourTable t[/code] |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-06-25 : 13:39:25
|
Where do you want to show data?If you use reports, group the report by Custnumber and reset recordnumber for each groupMadhivananFailing to plan is Planning to fail |
 |
|
sqlserverdeveloper
Posting Yak Master
243 Posts |
Posted - 2008-06-25 : 16:35:41
|
quote: Originally posted by madhivanan Where do you want to show data?If you use reports, group the report by Custnumber and reset recordnumber for each groupMadhivananFailing to plan is Planning to fail
Actually I need to update the table itself. |
 |
|
|
|
|