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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Returning values

Author  Topic 

HCLollo
Starting Member

49 Posts

Posted - 2005-06-27 : 05:07:25
First of all hi to everyone!
I've always been troubled with a little problem: is it possible
to have a code returned from an insert? I mean, let's imagine
I have a very simple table like:

ID
Name

When I do an insert, can I also have "something" return me the
ID it just entered? ID is of course an autoincrementing field
used as the primary key.

Thanks in advance,
HCL

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-06-27 : 05:16:38
Post sample data with expected result

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

rockmoose
SQL Natt Alfen

3279 Posts

Posted - 2005-06-27 : 05:23:34
Look up SCOPE_IDENTITY() and @@IDENTITY in BOL.
SCOPE_IDENTITY() is the preferred method.

rockmoose
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-06-27 : 05:36:15
and also this one
Select IDENT_CURRENT('tableName')
will return the Id just entered

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -