'SQL Incremental Value for Existing Column
I have a table with the below structure in sql server and would like to create an update stored procedure to set the value for seq_num column.
| fname | lname | orderid | seq_num |
|---|---|---|---|
| Torrey | Venard | 246 | 376987 |
| Gabey | Tate | 247 | 376988 |
| Germaine | Ferminger | 248 | 376989 |
| Nikita | Sharplin | 249 | 376990 |
| Boyd | Rannigan | 250 | 376991 |
| Claretta | Paoli | 251 | 376992 |
| Barn | Kulver | 252 | 376993 |
| Torrey | Venard | 253 | 376994 |
| Gabey | Tate | 254 | NULL |
| Germaine | Ferminger | 255 | NULL |
| Nikita | Sharplin | 256 | NULL |
| Boyd | Rannigan | 257 | NULL |
The total rows is about 20k. Ideally we should have this column as an auto increment, but what we are looking for is to fill in the NULLs with the next number like below:
| fname | lname | orderid | seq_num |
|---|---|---|---|
| Torrey | Venard | 246 | 376987 |
| Gabey | Tate | 247 | 376988 |
| Germaine | Ferminger | 248 | 376989 |
| Nikita | Sharplin | 249 | 376990 |
| Boyd | Rannigan | 250 | 376991 |
| Claretta | Paoli | 251 | 376992 |
| Barn | Kulver | 252 | 376993 |
| Torrey | Venard | 253 | 376994 |
| Gabey | Tate | 254 | 376995 |
| Germaine | Ferminger | 255 | 376996 |
| Nikita | Sharplin | 256 | 376997 |
| Boyd | Rannigan | 257 | 376998 |
any thoughts suggestions would be greatly appreciated!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
