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

解决方案 »

  1.   

    没必要循环插入,你将@maxcount当成dataid的一个偏移量就是,一次插入。
      

  2.   

    ccc表字段增加一个bh(编号)字段,bh不是自动增加
    ---------------
    你把这个字段设置成自动增加,那更简单,直接:insert into ccc(id,other) select id,other from deleted
      

  3.   


    就是要求不能用自动增加的。insert into ccc(bh,id,other) select isnull(@maxcount,0)+dataid,id,other from #tempjsxxb
    这句我先看看行不行^_^ 我担心isnull(@maxcount,0)+dataid 不会变,会一直是一个数值
      

  4.   

    create table #ccc (bh int)select top 3 dataid=identity(int,1,1) into #1 from syscolumns
    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
      

  5.   

    太帅了,Limpire  太崇拜你了,果然是这样的感激之情不知道怎么表达了~~谢谢谢谢  果然变了,,,^_^ 
    太感谢了^_^呆会分数奉上,我先改改代码 啊哈
      

  6.   

    set @maxcount=(select top 1 bh from ccc order by bh desc)--取得ccc内 bh 最大值
    -->改为下面会快点
    select @maxcount=max(bh) from ccc