--这个可以吗?格式有点不合你的要求.select 一审=(case FCheckLevel when 1 then FCheckMan end),
       二审=(case FCheckLevel when 2 then FCheckMan end), 
       三审=(case FCheckLevel when 3 then FCheckMan end),
       四审=(case FCheckLevel when 4 then FCheckMan end),
       五审=(case FCheckLevel when 5 then FCheckMan end),
       六审=(case FCheckLevel when 6 then FCheckMan end)
from aa
/*测试结果
一审          二审          三审          四审          五审          六审          
----------- ----------- ----------- ----------- ----------- ----------- 
16422       NULL        NULL        NULL        NULL        NULL
NULL        16421       NULL        NULL        NULL        NULL
NULL        16422       NULL        NULL        NULL        NULL
NULL        NULL        16397       NULL        NULL        NULL
NULL        NULL        16422       NULL        NULL        NULL
NULL        NULL        16423       NULL        NULL        NULL
NULL        NULL        NULL        16394       NULL        NULL(所影响的行数为 7 行)
*/

解决方案 »

  1.   

    上面的格式不能缩上去吗?
    先谢 mschen(老陈),我看一下,继续顶,
      

  2.   

    一审=isnull((case FCheckLevel when 1 then FCheckMan end),''),
      

  3.   

    我加了个临时表试了下,好像不行,建表如下,想再试的直管拷去
    create table table1 (
    FCheckLevel int,
    FCheckMan char(10))insert into table1
    select 1,'16422'
    union all select 2,'16422'
    union all select 2,'16421'
    union all select 3,'16422'
    union all select 3,'16423'
    union all select 3,'16397'
    union all select 4,'16394'
      

  4.   

    up
    如果不行我就不用dbgrid绑定了
      

  5.   

    --示例--测试数据
    create table table1 (FCheckLevel int,FCheckMan char(10))
    insert into table1
    select 1,'16422'
    union all select 2,'16422'
    union all select 2,'16421'
    union all select 3,'16422'
    union all select 3,'16423'
    union all select 3,'16397'
    union all select 4,'16394'
    go--查询处理
    select 
    一审=max(case FCheckLevel when 1 then FCheckMan else '' end),
    二审=max(case FCheckLevel when 2 then FCheckMan else '' end),
    三审=max(case FCheckLevel when 3 then FCheckMan else '' end),
    四审=max(case FCheckLevel when 4 then FCheckMan else '' end),
    五审=max(case FCheckLevel when 5 then FCheckMan else '' end),
    六审=max(case FCheckLevel when 6 then FCheckMan else '' end)
    from(
    select FCheckLevel,FCheckMan,id=(
    select count(*) from table1 
    where FCheckLevel=a.FCheckLevel and FCheckMan<=a.FCheckMan)
    from table1 a
    )a group by id
    go--删除测试
    drop table table1/*--测试结果一审         二审         三审         四审         五审         六审         
    ---------- ---------- ---------- ---------- ---------- ---------- 
    16422      16421      16397      16394                           
               16422      16422                                      
                          16423                                      (所影响的行数为 3 行)
    --*/