想用isnull函数,但是select出来的不是null值

westuser 2007-12-18 11:17:51
select col1 from tbl1 where 1=2
故意给个假条件,想查出一空行来,怎样才能使col1为null值
...全文
261 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
lwl0606 2007-12-18
  • 打赏
  • 举报
回复


select top 1 null as col1 from tbl1 where 1=1


带from 的时候,结果集中没有符合调节的记录是不会出数据的
wzy_love_sly 2007-12-18
  • 打赏
  • 举报
回复
select top 1 null from @tb
dawugui 2007-12-18
  • 打赏
  • 举报
回复
select null col

/*
col
-----------
NULL

(1 行受影响)
*/
dawugui 2007-12-18
  • 打赏
  • 举报
回复
select col = case when getdate() > getdate() - 1 then 'null' end

/*
col
----
null

(1 行受影响)
*/
fcuandy 2007-12-18
  • 打赏
  • 举报
回复
where 1=2
这个条件恒不成立,所以取不到行,自然得不到结果集中某列为null的结果.

直接 SELECT NULL 即可.
windlysnowly 2007-12-18
  • 打赏
  • 举报
回复
select isnull(name,'null')
from table
wzy_love_sly 2007-12-18
  • 打赏
  • 举报
回复
declare @tb table (id int)
insert into @tb select 1
insert into @tb select 2
insert into @tb select 3

select top 1 id=null from @tb
/*
id
NULL
*/
hui_hui_2007 2007-12-18
  • 打赏
  • 举报
回复
select null as 列名
JL99000 2007-12-18
  • 打赏
  • 举报
回复
select null as col from tabl1
select (case when ‘条件’ then ‘值’ else null end) as col from tabl1
中国风 2007-12-18
  • 打赏
  • 举报
回复
select col1=isnull(null,'')--测试isnull
--------
select col1 from tbl1 where col1 is null--加上条件
lhsxsh 2007-12-18
  • 打赏
  • 举报
回复
select col1 from tbl1 where col1 is null
alanzhou 2007-12-18
  • 打赏
  • 举报
回复
select * from table where id is null

34,588

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧