CREATE PROCEDURE getnewid
@Vpm varchar(50),
@Vxh varchar(50),
@Vid integer output
AS
declare @Icount integer
select @Icount=[id] from ok where pm=@vpm and xh=@vxh
if (@Icount=null) /*数据表中没有相同的,添加记录*/
begin
insert into ok(pm,xh) values(@vpm,@vxh)
select @Vid=@@identity
end
else if(@icount>0)
begin
select @vid=@icount
end
Go
我没有测试,如果成功,记得给我加分.
@Vpm varchar(50),
@Vxh varchar(50),
@Vid integer output
AS
declare @Icount integer
select @Icount=[id] from ok where pm=@vpm and xh=@vxh
if (@Icount=null) /*数据表中没有相同的,添加记录*/
begin
insert into ok(pm,xh) values(@vpm,@vxh)
select @Vid=@@identity
end
else if(@icount>0)
begin
select @vid=@icount
end
Go
我没有测试,如果成功,记得给我加分.
@myPM varchar(20),
@myXH varchar(20),
@myID Integer output
AS
DECLARE
@myCount integer
select @myCount =ID from myTable where PM=@myPM and XH= @myXH
if @@ROWCOUNT =0
begin
insert into myTable(pm,xh) values( @myPM,@myXH)
select @myID = @@identity
end
else
select @myID = @myCount
测试成功,记得给我加分.