如果姓名不重复create table a ( name varchar(10),age int )
insert into a
select 'Michael'     ,20
union all
select 'John'        ,23
union all
select 'Mary'        ,24select * into b from adeclare @i int
select @i=count(1) from b
while @i>0
begin
select top 1 * from b 
delete b
where name in (select top 1 name from b)
set @i=@i-1
endname       age         
---------- ----------- 
Michael    20(所影响的行数为 1 行)
(所影响的行数为 1 行)name       age         
---------- ----------- 
John       23(所影响的行数为 1 行)
(所影响的行数为 1 行)name       age         
---------- ----------- 
Mary       24(所影响的行数为 1 行)
(所影响的行数为 1 行)

解决方案 »

  1.   

    --生成测试数据
    create table 表1(name varchar(10),age int)
    insert into 表1 select 'Michael',20
    insert into 表1 select 'John   ',23
    insert into 表1 select 'Mary   ',24
    GO--借助含自增列的表变量实现循环处理过程
    declare @t table(id int identity(1,1),name varchar(10),age int)
    declare @i int,@name varchar(10),@age int
    set @i = 1insert into @t select * from 表1select @name=name,@age=age from @t where id=@i
    while @@rowcount<>0
    begin
        print 'name='+@name+';age='+rtrim(@age)
        set @i=@i+1
        select @name=name,@age=age from @t where id=@i
    end
    go/*
    name=Michael;age=20
    name=John   ;age=23
    name=Mary   ;age=24
    */--删除测试数据
    drop table 表1
      

  2.   

    我也很想知道,实际中总是碰到要处理大量数据,比如生成1000条数据的清单,对应的主单,同时在同一transaction中还需要生成其他相关的处理,大家碰到数据的处理量比较大,后台生成数据又比较多时,一般采用哪些优化的方法?设计采用的是三层架构,网络传输虽然是专线,但是终端用户在不断增加,业务量也在不断增加,预计可能还要翻倍,不知道如何处理,来这里学习,也请高手指点一二,谢谢!
      

  3.   

    游标的确是很方便,编程的效率提高了,但是现在服务端的数据还很少,将来数据一多,呵呵,反正是客户自己要求使用游标的,还给了使用的coding rule,到时runtime的时候就怪不得我们了。
      

  4.   

    对了,问一下有开发经验的兄弟,coding时碰到需要向客户确定的事情,但是又无法得到及时回答的时候,一般会怎么做,以方便以后的工作?
      

  5.   

    coding的时候怎么还会要向客户确定,除非:
    1、需求变更 
       这个时候肯定要做补充合同 来说明 功能变更以及工期的问题
    2、设计不合理,那就是自己的责任了
       这个就难说了 如果客户同意 可做补充合同 
       客户一定要按原合同执行  那你就承担责任吧
      

  6.   

    准备在06的元旦结贴,纯顶的朋友一人一分,回答问题的十分。乘此在多问一下,我在作为服务器的机器上用sa登录,也就是只要用拥有足够权限的帐户就可以对存贮在其上的store procedure进行debug,但是我如果从远端用查询分析器对存在server上的store procedure进行debug时,就是无法单步执行,断点设了也没用,那个debug按钮条上除了执行和设/取消断点的按钮可以点,其他都是灰色的(比如step over,step in等),而且我也用sa帐户进行登录操作也不行,请问兄弟们知道怎么从远程对server上的存储过程debug?