create procedure up_adddate(@name  varchar(50), @km_name  varchar(50), @secore  int)
as 
set nocount on declare @xh_code  intselect @xh_code = 序号 from table_name where 姓名= @name set @xh_code += 1insert into table_name values('张三',@xh_code, @km_name, @secore)
return 
go

解决方案 »

  1.   


    if object_id('tb') is not null
      drop table tb
    go
    create table tb([姓名] varchar(10), [序号] int,  [科目] varchar(10),  [分数] int)
    insert into tb
    select '张三',    1,  '语文',  85 union all 
    select '李四',    1,  '语文',  80 union all
    select '李四',    2,  '数学',  90 insert into tb
       select distinct [姓名], 
           (select max([序号])+1 from tb where [姓名]=a.[姓名]) [序号],
           '体育' [科目], 
           90 [分数]  
    from tb aselect * from tb order by [姓名],[序号]
    /*
    姓名   序号   科目   分数
    李四   1     语文   80
    李四   2     数学   90
    李四   3     体育   90
    张三   1     语文   85
    张三   2     体育   90
    */