sql库中有表T1,内容如下: ID C1  C2  C3 
1  1   2   Null 
2  1   2   5 判断C3是否为空,如果为空,C3值显示为C1+C2,如果不为空,C3为本身值,显示出来用一条select实现 也就是执行完select.....from T1语句要求显示 ID  C1  C2  C3 
1   1   2   3 
2   1   2   5谢谢

解决方案 »

  1.   

    select ID,C1,C2,isnull(C3,C1+C2) as C3 from T1
      

  2.   


    declare @test float
    set @test=2.10
    select  (case when (substring(ltrim(@test),len(@test),1))='0'
    then convert(varchar(100),convert(decimal(18,1),@test)) else
    convert(varchar(100),@test) end) as test1 declare  @t table (id int,a int,b int ,c int)
    insert into @t
    select 1,2,3,4 union all
    select 2,5,6,nullselect * from @t
    /*
    1 2 3 4
    2 5 6 NULL
    */
    select id,a,b,isnull(c,a+b) from @t
    /*
    1 2 3 4
    2 5 6 11
    */