就是num数量列大于1 的就拆分成2行,请高手帮忙

解决方案 »

  1.   

    select code,name,num 
    into #temp
    from temp
    where num=1declare @i int
    declare @code char(3)
    declare @name varchar(50)
    declare @num  int
    declare cur_devide cursor for
      select code,name,num
      from temp
      where num>1
    open cur_devide
    fetch next from cur_devide into @code,@name,@num
    while @@fetch_status = 0 
    begin
      set @i=0
      while @i<@num 
      begin
        insert into #temp values(@code,@name,1)
        set @i = @i + 1
      end
      fetch next from cur_devide into @code,@name,@num
    end
    close cur_devide
    deallocate cur_devideselect * from #temp order by code
      

  2.   

    谢谢 EastboyEastboy(鬼谷游侠)  ,在看看其他高手有没有更好的办法了!
      

  3.   

    很简单啊,num=1的select1遍,num>1的select2遍啊