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 |
|
ganeshkumar08
Posting Yak Master
187 Posts |
Posted - 2008-05-02 : 03:17:30
|
| I am trying to reset an IDENTITY RowNumberback to 1 in a query when the Person's Name is the same. The following querycan be used agains the pubs database in SQL Server.I am trying to figure out where to place the section for the DBCC CHECKIDENT item in order to reset the RowNumber back to 1 when ever the lname column is the same. For example if the pub database had duplicate records for a given employee the RowNumber would reset back to 1.CREATE TABLE #RowNumber (RowNumber int IDENTITY (1, 1),emp_id char(9) )--DECLARE @seed int--SET @seed = 1--DBCC CHECKIDENT ('#RowNumber', RESEED , @seed) WITH NO_INFOMSGSINSERT #RowNumber (emp_id)SELECT emp_idFROM employeeORDER BY lnameSELECT RowNumber, e.emp_id, lname, fname, job_idFROM #RowNumber r JOIN employee eON r.emp_id = e.emp_idORDER BY RowNumberDROP TABLE #RowNumberGanesh |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-02 : 03:33:00
|
| Why do you want to do that? |
 |
|
|
ganeshkumar08
Posting Yak Master
187 Posts |
Posted - 2008-05-02 : 04:45:40
|
| I am trying to learn resetting again and again in the table |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-05-02 : 04:48:32
|
| But that will cause duplicate values to be populated in table for field |
 |
|
|
|
|
|