select identity(int,0,1) flag,* into #临时表 from 你的表select
max(case when flag%4=0 then name end) 列1,
max(case when flag%4=1 then name end) 列2,
max(case when flag%4=2 then name end) 列3,
max(case when flag%4=3 then name end) 列4
from #临时表 group by flag/4go
drop table #临时表

解决方案 »

  1.   

    MeId        Name                 
    ----------- -------------------- 
    1           aaa
    2           bbb
    3           ccc
    4           ddd
    5           eee
    6           fff
    7           ggg
    8           hhh(所影响的行数为 8 行)列1                   列2                   列3                   列4                   
    -------------------- -------------------- -------------------- -------------------- 
    NULL                 aaa                  bbb                  ccc
    ddd                  eee                  fff                  ggg
    hhh                  NULL                 NULL                 NULL(所影响的行数为 3 行)警告: 聚合或其它 SET 操作消除了空值。
      

  2.   

    大力,,好象,第1列第1行总是NULL呀。
      

  3.   

    大力,,好象,第1列第1行总是NULL呀。
    ------------------------
    大力的没有错。你的MeId 是重1开始的,你看看大力的identity(int,0,1)是重0开始的。如果按照你的写法,应该用MeId-1代替才可以。