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)
 retrieving a newly inserted unique identifier

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-08-23 : 07:34:07
Gerry writes "I've been trying to find a way to retrieve the unique identifier of a newly inserted row.

I have a table with the primary key defined on a unique identifier type column. I gather information from a client through an ASP web page and insert the data into the table. Upon inserting the data, the default value for the unique identifier calls the NewID() function. However, I cannot seem to find something comparable to @@IDENTITY as used in the below code.


Dim db,rcs,new_identity

'Create a database connection
Set db = Server.CreateObject("adodb.connection")
db.Open "DSN=MyDSN"

'Execute the INSERT statement and the SELECT @@IDENTITY
Set rcs = db.execute("insert into tablename (fields,..) " & _
"values (values,...);" & _
"select @@identity").nextrecordset

'Retrieve the @@IDENTITY value
new_identity = rcs(0)



Any help would be greatly appreciated.

Gerry"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-23 : 07:38:17
See if this helps you
http://vyaskn.tripod.com/retrieve_guid_value_like_identity.htm

Madhivanan

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

bell27

4 Posts

Posted - 2005-08-23 : 11:03:45
Thats the way it is done do you not think so.


<edit> spam links removed </edit>
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-24 : 02:05:15
quote:
Originally posted by bell27

Thats the way it is done do you not think so.


<edit> spam links removed </edit>


Which way?

Madhivanan

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

- Advertisement -