刚才没说明白,贴已结,发帖再问?
直接上代码吧drop table #tbcreate table #tb(autoid int identity(581080,1),行号 int,b varchar(10))insert #tb (b)
select 'aaa' union all
select 'bbb' union all
select 'ccc' union all
select 'ddd' union all
select 'eee'
select *
from #tb/*(所影响的行数为 5 行)autoid      行号          b          
----------- ----------- ---------- 
     581080 NULL        aaa
     581081 NULL        bbb
     581082 NULL        ccc
     581083 NULL        ddd
     581084 NULL        eee(所影响的行数为 5 行)*/--我想用代码加上行号,实现
/*
autoid      行号          b          
----------- ----------- ---------- 
     581080 1        aaa
     581081 2        bbb
     581082 3        ccc
     581083 4        ddd
     581084 5        eee(所影响的行数为 5 行)*/

解决方案 »

  1.   

    drop table #tbcreate table #tb(autoid int identity(581080,1),行号 int,b varchar(10))insert #tb (b)
    select 'aaa' union all
    select 'bbb' union all
    select 'ccc' union all
    select 'ddd' union all
    select 'eee'
    declare @i int
    set @i = 0
    update #tb
    set 行号 = @i,@i+=1select *
    from #tbautoid      行号          b
    ----------- ----------- ----------
    581080      1           aaa
    581081      2           bbb
    581082      3           ccc
    581083      4           ddd
    581084      5           eee(5 行受影响)
      

  2.   


    create table #tb(autoid int identity(581080,1),行号 int,b varchar(10))insert #tb (b)
    select 'aaa' union all
    select 'bbb' union all
    select 'ccc' union all
    select 'ddd' union all
    select 'eee'update #tb
    set 行号 =autoid-581079
    select *
    from #tbdrop table #tb--581080 1 aaa
    --581081 2 bbb
    --581082 3 ccc
    --581083 4 ddd
    --581084 5 eee
      

  3.   

    declare @i int
    set @i = 0
    update #tb set @i=行号=@i+1select *
    from #tb
    借用一下數據
      

  4.   

    4楼的代码,什么意思呀?
    declare @i int
    set @i = 0
    update #tb set @i=行号=@i+1select *
    from #tb
      

  5.   

    本帖最后由 roy_88 于 2011-02-12 16:01:03 编辑
      

  6.   

    @variable已声明的变量,该变量将设置为 expression 所返回的值。SET @variable = column = expression 将变量设置为与列相同的值。这与 SET @variable = column, column = expression 不同,后者将变量设置为列更新前的值。