Wednesday, May 16, 2012

uses of @@identity:



DECLARE @NewId AS int
INSERT INTO HumanResources.Employees
  ( /* column names */)
  VALUES ( /* column values */)
SELECT @NewId = @@Identity




DECLARE @InsertedRows AS TABLE (Id int)
DECLARE @NewId AS INT
INSERT INTO HumanResources.Employees
  ( /* column names */)
OUTPUT Inserted.Id INTO @InsertedRows
  VALUES (/* column values */)
SELECT @NewId = Id FROM @InsertedRows


insert into tbl_record(record_type_id,isActive) Values(2,1)
declare @record_id int
declare @record_no varchar(15)
set @record_id=@@identity       
 select @record_no=record_no from tbl_record where record_id=@record_id
 select @record_no,@record_id
 

No comments:

Post a Comment