[thelist] ASP: @@Identity

Tab Alleman talleman at autobex.com
Fri Nov 10 16:21:47 CST 2000

too radical for 5 PM on Friday..  :)  I'll try it Monday morning and let you
know how it goes!

-----Original Message-----
From: thelist-admin at lists.evolt.org
[mailto:thelist-admin at lists.evolt.org]On Behalf Of Scott Dexter
Sent: Friday, November 10, 2000 4:25 PM
To: 'thelist at lists.evolt.org'
Subject: RE: [thelist] ASP: @@Identity

I use a trigger to insert into a second table instead of using @@Identity:

create Trigger tbGroupWWW_Add_tbGTSAudit
On dbo.tbGroupWWW
For Insert
Set nocount on
	If Update (uid)
			declare @id int
			Select @id=i.uid from inserted i
			Insert into tbGTSAudit(id) values (@id)

(the tbGTSAudit table has defaults on the other columns so the insert is
just the id value)

it grabs the auto-created id and uses it to insert into the second table.
Since @@Identity is a SERVER WIDE global variable, you can't be guaranteed
of its value through the lifetime of your loop. In other words, some other
process can change the @@Identity value without you knowing it.

dunno if this helps your specific scenario, but its an idea at least (you
can use a trigger for inserts, updates, deletes, or combinations thereof)

you would use it to do your Update below ....

work: http://www.ti3.com/
non: http://thinksafely.org/

> -----Original Message-----
> From: Tab Alleman [mailto:talleman at autobex.com]
> Problem: My @@Identity is experiencing a meltdown in the
> middle of my script
> and I don't know why.

> 			NewID = SELECT @@IDENTITY 'get the
> autonumber of the new record
> 			UPDATE MainTable SET (fields and
> values) WHERE ID = NewID

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

More information about the thelist mailing list