[thelist] Using @@Identity

Casey aspnet at thecrookstons.com
Tue Aug 23 19:14:00 CDT 2005


Serdar said:

I didn't catch the beginning of this thread, but have a look at
SCOPE_IDENTITY() , @@IDENTITY is global across the server(?), whilst
SCOPE_IDENTITY is for the current context.

Casey Replied:

Ok, thanks Serdar.  David pointed out the same thing.  I am a convert of
using SCOPE_IDENTITY()  instead of @@IDENTITY, but I just don't know HOW to
use them!!!!!!!!!!!!!!!!!!!

Everything is below....

~~~~~~~~~~~~~

I was able to get this far (see below) from:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_globals_50u1.asp

Now I just need to know how to retreive the value of Identity. All this is
being done in ASP.NET using VB and an MS SQL Database.  The colum in
question is doc_id which is set as the auto-incrementing Primary Key.

Dim conAddDoc As SqlConnection = New
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings("MccCon
String"))

Dim strInsert As String = "Insert MCCIME_Doctor (fname, lname, specialty,
...) VALUES (@fname, @lname, @specality, ...) SELECT @@IDENTITY AS
'Identity'"

Dim cmdInsert As SqlCommand = NEW SqlCommand(strInsert, conAddDoc)

conAddDoc.Open
cmdInsert.ExecuteNonQuery()
conAddDoc.Close



--

* * Please support the community that supports you.  * *
http://evolt.org/help_support_evolt/

For unsubscribe and other options, including the Tip Harvester
and archives of thelist go to: http://lists.evolt.org
Workers of the Web, evolt !




-- 
Cheers,
Serdar Kilic
http://weblog.kilic.net/



More information about the thelist mailing list