SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 retrieving the ID field
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ronin2307
Posting Yak Master

126 Posts

Posted - 07/18/2006 :  15:48:34  Show Profile  Reply with Quote
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

USA
36953 Posts

Posted - 07/18/2006 :  15:54:13  Show Profile  Visit tkizer's Homepage  Reply with Quote
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

Edited by - tkizer on 07/18/2006 15:55:12
Go to Top of Page

ronin2307
Posting Yak Master

126 Posts

Posted - 07/18/2006 :  17:33:32  Show Profile  Reply with Quote
thanx. I found the article on msdn. thanx anyway
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000