Home All Groups Group Topic Archive Search About

How to return the auto increment fields?

Author
11 Aug 2006 4:54 AM
Cylix
Sorry for newbie question,
I am going to create a stored procedure for two task:

Inset a row to a table, and
return the Identity field(which is auto-increment) to the program.

Thanks.

Author
11 Aug 2006 5:06 AM
Adi
You can get the new value with select @@identity or select
scop_identity().  You can find more about both functins in Books on
line.

Adi

Cylix wrote:
Show quote
> Sorry for newbie question,
> I am going to create a stored procedure for two task:
>
> Inset a row to a table, and
> return the Identity field(which is auto-increment) to the program.
>
> Thanks.
Author
11 Aug 2006 6:31 AM
Jens
If you are on SQl Server 2005, you can also use the ne OUTPUT clause
which will allow you to pass back a variable within a statement. In C#
you would probably add a parameter with either the direction IN  or
IN/OUT.

HTH, Jens Suessmeyer.

---
http://www.sqlserver2005.de
---

AddThis Social Bookmark Button