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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 help please..

Author  Topic 

my_aro
Yak Posting Veteran

50 Posts

Posted - 2006-05-14 : 13:13:49
hello

can 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
Go to Top of Page

my_aro
Yak Posting Veteran

50 Posts

Posted - 2006-05-14 : 13:19:36
yes the one for a record you just added..
Go to Top of Page

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.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

my_aro
Yak Posting Veteran

50 Posts

Posted - 2006-05-14 : 13:45:48
i tried SELECT SCOPE_IDENTITY() but it gives me null
Go to Top of Page

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.

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -