select (select count(*) from tablename where id<=A.id) as id,field1,field2....... from tablename A

解决方案 »

  1.   

    to winsock2000 (winsock) 
    你的意思是select出来以后是1/2/3/4,还是在数据库中update成1/2/3/4?如果是前一种看看j9988(j9988)的,如过是后一种,你估计要加触发器来实现了。
      

  2.   

    to : CoolAbu
    谢谢,是在数据库中把序号修改成1/2/3/4!不知道改如何做呢?谢谢!
      

  3.   

    下面是处方器的编写方法,具体的还是要你自己来写,还要用到临时表的,不太推荐用触发器。create trigger tr_table_main_update 
    on table_main
    for update
    as 
    update table_mx
    set type=i.type,shul=i.shul
    from inserted i,deleted d,table_mx x
    where i.bianh=d.bianh
    and d.type=x.type
    and d.shul=x.shulgo
      

  4.   

    我们在pb是用一个循环函数来实现此功能的,sql 中可以这样,未测试declare  @ll_id int,
             @i     int
    select @i = 1declare update_id cursor scroll_locks
      for select id from tablename where condition
      for update of idfetch next from update_id into @ll_id
    while (@@fetch_status <> -1) 
    begin
      update tablename set id = @i where current of update_id
      fetch next from update_id into @ll_id
      select @i = @i + 1
    end 
    deallocate update_id