create table ta(id int identity(1,1),name varchar(5)) create proc test @name varchar(2),@i int output as insert ta select @name return @@identityexec test 'aa'
create table test(id int identity(1,1),code varchar(20)) gocreate procedure sp_test(@code varchar(20),@id int output) as begin insert into test values(@code) select @id=@@identity return end godeclare @id intexec sp_test 'AAAA',@id output select @id exec sp_test 'BBBB',@id output select @id exec sp_test 'CCCC',@id output select @idselect * from test godrop procedure sp_test drop table test go
create table test(id int identity(1,1),code varchar(20)) gocreate procedure sp_test(@code varchar(20),@id int output) as begin insert into test values(@code) select @id=@@identity return end godeclare @id intexec sp_test 'AAAA',@id output select @id /* ----------- 1 */exec sp_test 'BBBB',@id output select @id /* ----------- 2 */exec sp_test 'CCCC',@id output select @id /* ----------- 3 */select * from test /* id code ----------- -------------------- 1 AAAA 2 BBBB 3 CCCC */ godrop procedure sp_test drop table test go
create table ta(id int identity(1,1),name varchar(5))alter proc test @name varchar(2),@i int output as insert ta values( @name) select @@identity declare @i int exec test 'bb',@i output
create proc test @name varchar(2),@i int output
as
insert ta
select @name
return @@identityexec test 'aa'
gocreate procedure sp_test(@code varchar(20),@id int output)
as
begin
insert into test values(@code)
select @id=@@identity return
end
godeclare @id intexec sp_test 'AAAA',@id output
select @id
exec sp_test 'BBBB',@id output
select @id
exec sp_test 'CCCC',@id output
select @idselect * from test
godrop procedure sp_test
drop table test
go
gocreate procedure sp_test(@code varchar(20),@id int output)
as
begin
insert into test values(@code)
select @id=@@identity return
end
godeclare @id intexec sp_test 'AAAA',@id output
select @id
/*
-----------
1
*/exec sp_test 'BBBB',@id output
select @id
/*
-----------
2
*/exec sp_test 'CCCC',@id output
select @id
/*
-----------
3
*/select * from test
/*
id code
----------- --------------------
1 AAAA
2 BBBB
3 CCCC
*/
godrop procedure sp_test
drop table test
go
as
insert ta values( @name)
select @@identity
declare @i int
exec test 'bb',@i output
用这个