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
 Transact-SQL (2000)
 retrieving the ID field

Author  Topic 

ronin2307
Posting Yak Master

126 Posts

Posted - 2006-07-18 : 15:48:34
I'm sure my problem is not unique, but I am having a hard time thinking of a way to solve it so here it is:
I have a VB form with some fields on it, which are used to create a new entry in one of my SQL tables. The design kinda goes like this: all fields are mandatory and in addition to that the primary field (fid) in the table is the identity field which self increments.
So the question is: how do I retrieve the id value from the fid field for my newly created entry? To make things harder, it is possible that two entries can have ALL fields identical.

thanx

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-07-18 : 15:54:13
You need to capture the value of SCOPE_IDENTITY() directly after the insert is performed.

DECLARE @i int

INSERT INTO ...

SET @i = SCOPE_IDENITY()

Tara Kizer
Go to Top of Page

ronin2307
Posting Yak Master

126 Posts

Posted - 2006-07-18 : 17:33:32
thanx. I found the article on msdn. thanx anyway
Go to Top of Page
   

- Advertisement -