10 V 0
11 X 212 P 0
14 E 0
15 D 0
16 G 1317 J 0
18 K 0
2跟13按  条件在两列显示

解决方案 »

  1.   


    declare @t table (id int,name varchar(1),value int)
    insert into @t
    select 10,'V',0 union all
    select 11,'X',2 union all
    select 12,'P',0 union all
    select 14,'E',0 union all
    select 15,'D',0 union all
    select 16,'G',13 union all
    select 17,'J',0 union all
    select 18,'K',0select *,
    col1=case when value=2 then '2' else null end,
    col2=case when value=13 then '13' else null end 
    from @t
    /*
    id          name value       col1 col2
    ----------- ---- ----------- ---- ----
    10          V    0           NULL NULL
    11          X    2           2    NULL
    12          P    0           NULL NULL
    14          E    0           NULL NULL
    15          D    0           NULL NULL
    16          G    13          NULL 13
    17          J    0           NULL NULL
    18          K    0           NULL NULL
    */