case columnName 就能判断该字段不为Null.
例如
create table test(id int identity,username varchar(20))
go
insert into test(username) values('张三')
go
insert into test(username) values('李四')
go
insert into test(username) values(null)
go
insert into test(username) values(null)
--eg.
select case username when username then username else '无名氏' end as username from test
结果如下
1 | 张三 |
2 | 李四 |
3 | 无名氏 |
4 | 无名氏 |