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

一个好象简单的select句子,该如何解决

2012-02-15 
一个好象简单的select句子有表TIDNAME1tom2mike3johnselectidfromTwhereid4返回的是IDnull要求返回的是ID

一个好象简单的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)

热点排行