create proc proc_test2 ( @a int )
as
begin
  set nocount on
  select case when (b is not null or b <> ‘’) and (c is not null or c <> ‘’) then 'B('+ B+ ')'+ 'C('+ C+ ')'
              when (b is not null or b <> ‘’) and (c is null or c = ‘’) then 'B('+ B+ ')'
      when (b is null or b = ‘’) and (c is not null or c <> ‘’) then 'C('+ C+ ')' 
        end 
  from test2 where a=@a
  set nocount off
end
現在不能轉可用分了.你如果需要可用分,我可以給你.

解决方案 »

  1.   

      select case when b is not null and c is not null then 'B('+ B+ ')'+ 'C('+ C+ ')'
                  when b is not null and c is null then 'B('+ B+ ')'
          when b is null and c is not null then 'C('+ C+ ')' 
            end 
      from test2 where a=1
      执行出来什么结果?
      

  2.   

    TO:sky_blue(蓝天)他只走第一条,比如C为空就返回B(01)C()大哥,第二个问题怎么解决啊?我快没分了!
      

  3.   

    呵呵! 对所有字段 TRIM 一下不就搞定了。
      

  4.   

    SELECT (CASE TRIM(b) WHEN null THEN null else 'B('+b+')')+(CASE TRIM(c) WHEN null THEN null else 'C('+c+')') AS result
    FROM TABLE where A=@A; 如果 trim 不行 改成 alltrim(b)_ , lefttrim(righttrim(b)) 试试
      

  5.   

    按照zhuzhichao(竹之草)(出关了…) 的做法做.
    你有个概念错误:
    ''不等于null
      

  6.   

    在oracle中 trim('   ')=NULL 在sql server 中我这没环境测,不过可以加上 or '' 搞定
      

  7.   

    update table set b = null where rtrim(b) = ''
    update table set c = null where rtrim(c) = ''