` Printed Icetips Article

Icetips Article



SQL Related Articles: Retrieving Identity value from MSSQL
2003-11-24 -- Sebastian Streiger
 
Newsgroups: softvelocity.public.clarion6

Access:Customer.TryInsert()
Customer{Prop:SQL} = 'SELECT @@IDENTITY'
If Access:Customer.TryNext() <> Level:Benign
  !Something went wrong here
End
MESSAGE(Customer:SysId) !Now you should get what you wanted.

!This will return the value of the last identity inserted in the current session.
!No posible clash with other users
!I'm asumming that Customer:SysId is the first field in the Customers table.
!If it's not you should add dummy values to the select so that the identity fits the
proper buffer position

Just one warning. @@IDENTITY is a MSSQL variable, it won't work with another back-end.
Also it returns the last inserted identity of the current session, no matter wich tabl;e
was the last that was inserted into.
So you should be aware that a trigger for example can make the previous code errorneous.

Hpe this helps

--
Sebastián Streiger
IT Department
Red Megatone



Printed November 23, 2024, 6:19 am
This article has been viewed/printed 35212 times.
Google search has resulted in 303 hits on this article since January 25, 2004.