我有一表 sy
xh int (自增)
xm varchar(4)
建存储过程如下
CREATE PROCEDURE syxm
@xm varchar(4),
@xh int output
as
insert into sy (xm)values(@xm)
Select @xh=@@IDENTITY
go
目的;在新增数据后返回xh
用查询分析器执行
declare @xm varchar (4),@xh int set @xm='bbbb' exec syxm @xm, @xh
能新增数据不能返回带自增列的序号
------解决方案--------------------
或者:
declare @xm varchar (4),@xh int set @xm='bbbb'
exec syxm @xm, @xh output
select @xh
------解决方案--------------------
最后面要查询的话 需要select @xh
------解决方案--------------------
- SQL code
declare @xm varchar (4),@xh int set @xm='bbbb' exec syxm @xm, @xh outputselect @xh
------解决方案--------------------
- SQL code
if object_id('sy') is not null drop table sygocreate table sy( xh int identity(1,1), xm varchar(4))goif object_id('up_tb') is not null drop procedure up_tbgocreate procedure up_tb (@xm varchar(4),@xh int output)as insert into sy (xm) values (@xm) select @xh=@@IDENTITYgodeclare @xh intexec up_tb '张三',@xh outputselect @xh/*-----------1(1 行受影响)*/