how do you return a record number once you insert data into a sql table?
Printable View
how do you return a record number once you insert data into a sql table?
SELECT @@IDENTITY will get you the id value inserted. You could return it in an OUTPUT parameter.
what is an OUTPUT parameter?
this is what i came up with....?
Code:create procedure [p_save_new] @sheetname varchar(1000), @sheetdata text, @categoryid int, @username nvarchar(50) as
insert into tblcheatsheet
(sheetname, sheetdata,categoryid,active)
values (@sheetname, @sheetdata, @categoryid , '1')
insert into tblWhoWhen
values(@@IDENTITY , @username, Getdate())
create procedure [p_save_new] @sheetname varchar(1000), @sheetdata text, @categoryid int, @username nvarchar(50), @ReturnValue INT OUTPUT as
insert into tblcheatsheet
(sheetname, sheetdata,categoryid,active)
values (@sheetname, @sheetdata, @categoryid , '1')
SELECT @ReturnValue = @@IDENTITY FROM tblcheatsheet
insert into tblWhoWhen
values(@ReturnValue , @username, Getdate())
what was wrong with the way i was doing it?