case when 的使用方式

==========代码实例,俩个条件判断,如果都不符合走else语句=================

SELECT
  TMRP.xm
  , TMRP.sj
  , TMRP.BGYX
  , TCUI.PHONE
  , TCUI.MAIL
  , CASE 
    WHEN TCUI.PHONE IS NOT NULL 
      THEN TCUI.PHONE 
    WHEN TMRP.sj IS NOT NULL 
      THEN TMRP.sj 
    ELSE '' 
    END aa
  , CASE 
    WHEN TCUI.MAIL IS NOT NULL 
      THEN TCUI.MAIL 
    WHEN TMRP.BGYX IS NOT NULL 
      THEN TMRP.BGYX 
    ELSE '' 
    END cc 
FROM
  V_MID_RS_PARTY TMRP 
  INNER JOIN T_CADRE_USER_INFO TCUI 
    ON TMRP.NUM_ID = TCUI.BASE_INFO_ID

===========查询结果==============

 

 

posted @ 2018-12-05 13:25  程序员小明1024  阅读(1360)  评论(0编辑  收藏  举报