读书人

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

发布时间: 2012-02-14 19:19:19 作者: rapoo

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

读书人网 >SQL Server

热点推荐