Except that the @@IDENTITY is the last inserted ID, if you have any triggers setup that insert then this could be affected, Scope_Identity() locks the ID getting to the current scope/view so remains unaffected by triggers etc
On 4/18/05, Robertson-Ravo, Neil (RX) <[EMAIL PROTECTED]> wrote: > SELECT @@IDENTITY is all you need. > > > -----Original Message----- > From: JediHomer [mailto:[EMAIL PROTECTED] > Sent: 18 April 2005 11:53 > To: CF-Talk > Subject: Re: Last ID inserted > > SET NOCOUNT ON > > INSERT INTO tableUsers (blah) > VALUES (moreblah) > > SELECT InsertedID = Scope_Identity() > > SET NOCOUNT OFF > > HTH > > On 4/18/05, Stuart Kidd <[EMAIL PROTECTED]> wrote: > > > > > > Hi guys, > > > > I am inserting to a few tables at once (ms-sql, cf7.0). > > > > One table will insert into the tableUsers and then I will insert into > tableQuestions. In tableQuestions i will want to put the contents of the > userID which i just inserted into tableUsers. > > > > Can anyone tell me how I can get the exact userID which I just inserted so > I can put into my tableQuestions table? > > > > I know of MaxID (or something like that) but i am worried that in some > cases there may be more than one person accessing the DB and I may grab the > incorrect information. > > > > Any ideas would be appreciated. Thanks, > > > > Saturday > > > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Logware (www.logware.us): a new and convenient web-based time tracking application. Start tracking and documenting hours spent on a project or with a client with Logware today. Try it for free with a 15 day trial account. http://www.houseoffusion.com/banners/view.cfm?bannerid=67 Message: http://www.houseoffusion.com/lists.cfm/link=i:4:203188 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=11502.10531.4 Donations & Support: http://www.houseoffusion.com/tiny.cfm/54