Syntax
LAST_ROW( columnName)
If previous command updated or inserted a row, we can read the value of the column of the last affected row. Otherwise, function will return NULL.
Example
use test;
declare @id bigint;
--create table with 2 identity columns
create table product(
id1 uniqueidentifier not null primary key,
id2 bigint not null default(AutoIdentity()),
name varchar);
--create table to store products transaction
create table [log] (
id1 bigint,
id2 bigint,
[time] datetime default(getdate()));
go; --execute create tables
--insert into products, and to log with the identity value of the products row
Insert into product(name) values('myproduct');
set @id = scope_identity();
Insert into [log](id1,id2) values(@id,@id+1);
select last_row(id1), last_row(id2)
Related