select field =(case id when 1 then 's_l' else 's_x' end),
fieldvalue=(case id when 1 then s_l else s_x end) from test

解决方案 »

  1.   

    不是这个意思
     id很多 获取id后 首先要去s_l字段 如果该字段的值为null 就去s_x 谢谢楼上的!
      

  2.   

    select field=case when S_L is null then 'S_X' else 'S_L' end,
           fieldvalue=case when S_L is null then S_X else S_L end
      from test
      

  3.   

    同意楼上的,一下是测试语句create table temp1
    (id int identity(1,1),
    s_x int,
    s_l int)
    insert into temp1(S_X)
    values(2)select * from temp1select field=case when S_L is null then 'S_X' else 'S_L' end,
           fieldvalue=case when S_L is null then S_X else S_L end
      from temp1