加多两个字段??什么意思??create table #t
(id int ,item char(10),id1 int ,item1 char(10))这样吗??

解决方案 »

  1.   

    可以實現
    先加個字段select identity(int,1,1)as ID,* into #temp from #t
    然後偶數放進一個表,奇數放一個表(以ID)
    1>然後用以個inner join
    再把2表合一表一定行
    2>用case when     提示:id1=case id when 0 then id
    .....
                           
      

  2.   

    Select Idd=Identity(Int,1,1),* Into #TT from #t Select 
    id ,
    item,
    (Select id from #TT Where Idd=A.Idd+1) As id1,
    (Select item from #TT Where Idd=A.Idd+1) As item1
    from #TT A
    Where Idd%2<>0--结果
    /*
    id item id1 item1
    1 1          2 1         
    3 1          5 21        
    21 231        61 11        
    */
      

  3.   

    create table #t
    (id int ,item char(10))insert into #t
    select 1,1
    union
    select 2,1
    union
    select 3,1
    union
    select 5,21
    union
    select 61,11
    union
    select 21,231select * from #t
    drop table #tselect identity(int,1,1) as Tid,* into #a from #tselect * into #b  from (select * from #a where Tid%2=1)T
    select TID,id as id1,item as item1 into #c  from(select * from #a where Tid%2=0)T
    select * from #c
    select * into #t from (select #b.id,#b.item,#c.id1,#c.item1 from #b,#c where #c.TID=#b.TID+1)T
    select * from #t
    ---刪除測試環境
    drop table #a,#b,#c
      

  4.   

    第2種方法請看
    paoluo(一天到晚游泳的鱼) ( ) 信誉:100