declare @maxcount int --保存ccc表内 bh 最大值set @maxcount=(select top 1 bh from ccc order by bh desc)--取得ccc内 bh 最大值select dataid=indentity(int,1,1),* into #tempccc from deleted --建立临时表,含有自动编号insert into ccc(bh,id,other) select isnull(@maxcount,0)+dataid,id,other from #tempjsxxb
---------------
你把这个字段设置成自动增加,那更简单,直接:insert into ccc(id,other) select id,other from deleted
就是要求不能用自动增加的。insert into ccc(bh,id,other) select isnull(@maxcount,0)+dataid,id,other from #tempjsxxb
这句我先看看行不行^_^ 我担心isnull(@maxcount,0)+dataid 不会变,会一直是一个数值
select top 4 dataid=identity(int,1,1) into #2 from syscolumns
declare @maxcount int --保存ccc表内 bh 最大值
set @maxcount=(select top 1 bh from #ccc order by bh desc)--取得ccc内 bh 最大值
insert #ccc select isnull(@maxcount,0)+dataid from #1
select * from #ccc
/*
bh
-----------
1
2
3
*/
godeclare @maxcount int --保存ccc表内 bh 最大值
set @maxcount=(select top 1 bh from #ccc order by bh desc)--取得ccc内 bh 最大值
insert #ccc select isnull(@maxcount,0)+dataid from #2
select * from #ccc
/*
bh
-----------
1
2
3
4
5
6
7
*/
godrop table #ccc,#1,#2
太感谢了^_^呆会分数奉上,我先改改代码 啊哈
-->改为下面会快点
select @maxcount=max(bh) from ccc