Cowboy
Mon Mar 03 18:00:49 CST 2008
But Bill, it is so much fun to get back the identity from the next record
inserted. What is coding without moving values? ;->
--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA
*************************************************
| Think outside the box!
|
*************************************************
"William Vaughn" <billvaNoSPAM@betav.com> wrote in message
news:4EDE7BC8-AC2D-40ED-8DFE-2E7D4C05ED30@microsoft.com...
> Ah, no. Unless this is Access/JET you should NOT use @@Identity to return
> the latest identity value.
> The correct way to handle identity value retrieval is SCOPE_IDENTITY as
> she said.
> Generally, one executes a batch that includes an extra SELECT to return
> the identity value after the INSERT. I would implement this in a stored
> procedure that also used RETURN to return a success/failure flag (0,1)
> along with the SCOPE_IDENTITY value as a second rowset (expensive) or an
> OUTPUT parameter.
>
> See my book for more details. It seems that now that Fawcett has
> disappeared, the magazine articles they were hosting are gone
> too--otherwise I would send you to an article on identity I wrote some
> time ago. Until I get that resurrected, this might do.
>
http://msdn2.microsoft.com/en-us/library/aa224821(SQL.80).aspx
>
> --
> __________________________________________________________________________
> William R. Vaughn
> President and Founder Beta V Corporation
> Author, Mentor, Dad, Grandpa
> Microsoft MVP
> (425) 556-9205 (Pacific time)
> Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
> ____________________________________________________________________________________________
> "HelloWorld" <no_mails_AT_to_me_.com> wrote in message
> news:upWnQlRfIHA.5280@TK2MSFTNGP02.phx.gbl...
>> Is your question to retrieve the identity value? in that case one
>> alternative is to query the @@Identity after your insert...
>>
>> select @@identity from TableName
>>
>>
>> "Luc" <Luc@discussions.microsoft.com> wrote in message
>> news:79B36FC9-BF47-405C-A446-B2DD0CA1D226@microsoft.com...
>>> Dear,
>>>
>>> how can I get the scope_identity after inserting records into the
>>> database
>>>
>>>
>>> <System.ComponentModel.DataObjectMethod(ComponentModel.DataObjectMethodType.Select,
>>> True)> _
>>> Public Function Insertdata(@Name, @firstname) as integer
>>>
>>> return adapter.insert(@name,@firstname)
>>>
>>> end function
>>>
>>>
>>> The return statement only returns 1 incase the insert was
>>> successful........this while I'm interested to get the last Id from this
>>> insert.
>>>
>>> your help is most appreciated!!
>>>
>>>
>>>
>>> --
>>> Best regards
>>> Nicole
>>
>>
>