declare @标志变量,@表变量 table (次序 int,标志 char(4),字段A char(4))
DECLARE Employee_Cursor CURSOR FOR
SELECT 标志 FROM 表 group by 标志
OPEN Employee_CursorFETCH NEXT FROM Employee_Cursor into @标志变量
WHILE @@FETCH_STATUS = 0
BEGIN
    insert @表变量 select identity(1,1),标志,字段A from 表 where 标志=@标志变量
    FETCH NEXT FROM Employee_Cursor into @标志变量
ENDCLOSE Employee_Cursor
DEALLOCATE Employee_Cursorselect * from @表变量 aaa

解决方案 »

  1.   

    SQL 2000 中用SQL语言???
      

  2.   

    有ID就好办了,没有ID汉字比较次序会乱。declare @a table(code varchar(10),type varchar(10))
     
    insert @a select 'J935',       '新眼'  
    union all select 'J935',       '染'      
    union all select 'J936',       '新制'   
    union all select 'J936',       '染'      
    union all select 'J937',       '新眼'  
    union all select 'J937',       '光'      
    union all select 'J937',       '染色'
    select (select count(*) from @a where code=a.code and type>=a.type) as cx,* from @a a order by code,cx    cx          code       type       
    ----------- ---------- ---------- 
    1           J935       新眼
    2           J935       染
    1           J936       新制
    2           J936       染
    1           J937       新眼
    2           J937       染色
    3           J937       光
      

  3.   

    declare @i int,@标志 char(10)
    set @i=1
    set @标志=''
    select cast(0 as integer) 次序,标志,字段A into #tmp from tablename order by 标志
    update #tmp
    set @i=case when 标志=@标志 then @i+1 else 1 end,
        @标志=case when COALESCE(@标志,'')=标志 then @标志 else 标志 end,
        次序=@i
    select * from #tmp
    drop table #tmp
      

  4.   

    从理论的角度讲,可以这样修改基本表:
    ALTER TABLE 表名
      ADD 次序 <数据类型> [完整性约束]