首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

新手问个一条SQL语句有关问题

2012-02-14 
新手问个一条SQL语句问题A表:bk_noamountstuff_datechg_date1100null2007-01-202200null2007-01-193300nu

新手问个一条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

热点排行