日期:2014-05-19  浏览次数:20498 次

新手问个一条SQL语句问题;
A表:
bk_no     amount       stuff_date           chg_date
  1               100           null                   2007-01-20
  2               200           null                   2007-01-19
  3               300           null                   2007-01-20
  4               400         2007-01-21           null

查询结果如下:
bk_no     amount       stuff_date           chg_date
  1               100         2007-01-20         2007-01-20
  2               200         2007-01-19         2007-01-19
  3               300         2007-01-20         2007-01-20
  4               400         2007-01-21           null

select   case   when   stuff_date=null   then   chg_date   else   stuff_date   end)   as   stuff_date,*   from   a;
为什么查询不出如上面的结果呢?谢谢~

------解决方案--------------------
stuff_date = null,格式不对。不能用等号的,试试stuff_date is null
------解决方案--------------------
select bk_no,amount,stuff_date = case when stuff_date is null then chg_date else stuff_date end,chg_date from tab1