日期:2014-05-18  浏览次数:20409 次

一个好象简单的select句子
有表T
ID   NAME
1     tom
2     mike
3     john

select   id   from   T   where   id=4
返回的是
ID
null

要求返回的是
ID
0

isnull   case   when   等试过都不行!

------解决方案--------------------
select id from T where id=4
union all
select 0 where not exists(select 1 from T where id=4)
------解决方案--------------------
select id = 0 where not exists (select 1 from t where id = 4)

------解决方案--------------------
select id from T where id=4
if id
case when null then '0 ' esle id end
end


这个可以用吗?我没试过,我是新手,高手们帮帮我们吧,这条可以用吗?
------解决方案--------------------
select id=isnull((select id from #b where id=4),0) from #b where id=4 union all select 0
------解决方案--------------------
select 0 as id where not exists (select 1 from t where id = 4)