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 |
|
my_aro
Yak Posting Veteran
50 Posts |
Posted - 2006-05-14 : 13:13:49
|
| hellocan anybody help me how to get the newest generated id in mssql server? |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-05-14 : 13:14:53
|
| Do you mean the one for a record you just added, or the most recent in the table [that anyone has added]?Kristen |
 |
|
|
my_aro
Yak Posting Veteran
50 Posts |
Posted - 2006-05-14 : 13:19:36
|
| yes the one for a record you just added.. |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2006-05-14 : 13:20:01
|
If it's in the same scope, you can use SELECT SCOPE_IDENTITY(). If it's in the same scope OR session(be aware of the difference and read Books Online), you can use @@identity. If it's just for a specific table, you can use IDENT_CURRENT. So many options, so small of a difference. Using the wrong one can really screw up your world though. MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
my_aro
Yak Posting Veteran
50 Posts |
Posted - 2006-05-14 : 13:45:48
|
| i tried SELECT SCOPE_IDENTITY() but it gives me null |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2006-05-14 : 14:23:05
|
| Did you read about the different options I gave you in Books Online? If not, read them. Try each, and let us know if you still need help. Books Online is included free with SQL Server. It's a great resource.MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
|
|
|