Hmm. Hadn't heard that before. Thanks for the tip! --Ben
S.Isaac Dealey wrote: > i'm not sure if that's thread-safe tho... I don't remember offhand > what set nocount does... but the @@identity variable is from any table > in any sql server session across the database or possibly the server, > not sure... SQL Server 2000 introduced a SCOPE_IDENTITY() function > which _is_ thread-safe... > > <cfquery> > insert stuff; > select scope_identity() as something; > </cfquery> > > This function ensures that the value returned is from the last table > inserted in your currently executing batch -- so if it's not in your > cfquery, it won't affect the result. (iirc including triggers on the > table you're inserting into which has been known to cause problems > with @@identity) ... so the rule of thumb is to use scope_identity() > if you can. > > > >><cfquery> >> set nocount on; >> insert stuff; >> select @@identity as something; >> set nocount off; >></cfquery> > > >>Just did this day before yesterday. :-) > > >>--Ben > > >>Phill B wrote: >> >>>I cant remember how to return the id from an insert. I >>>have searched >>>but I can't find what I'm looking for. Not to mention >>>people keep >>>buggin me making my job harder than it should be. :-| >>> >>> >>>Anyway, it is some thing like @@identity but I cant >>>remember. Little help? >>> > > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Special thanks to the CF Community Suite Silver Sponsor - New Atlanta http://www.newatlanta.com Message: http://www.houseoffusion.com/lists.cfm/link=i:4:187119 Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4 Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4 Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54