
SQL中如何判断字段NULL或者为空字符串
sql查询中,我想A字段为NULL或者为空字符串时显示B字段,否则显示A字段,怎么写sql语句呢?...
sql查询中,我想A字段为NULL或者为空字符串时显示B字段,否则显示A字段,怎么写sql语句呢?
展开
6个回答
展开全部
create table test
(
a varchar(20),
b varchar(10)
)
insert into test (b) values('b')
insert into test (a,b) values('','b')
insert into test(a,b) values ('a','b')
select case when a is null then b when a='' then b else a end from test
复制代码 ,粘贴,执行,直接可以看到结果
(
a varchar(20),
b varchar(10)
)
insert into test (b) values('b')
insert into test (a,b) values('','b')
insert into test(a,b) values ('a','b')
select case when a is null then b when a='' then b else a end from test
复制代码 ,粘贴,执行,直接可以看到结果
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select case when a is null then b when a='' then b else a end from 表 create table test
(
a varchar(20),
b varchar(10)
)
insert into test (b) values('b')
insert into test (a,b) values('','b')
insert into test(a,b) values ('a','b')
select case when a is null then b when a='' then b else a end from test
复制代码 ,粘贴,执行,直接可以看到结果
(
a varchar(20),
b varchar(10)
)
insert into test (b) values('b')
insert into test (a,b) values('','b')
insert into test(a,b) values ('a','b')
select case when a is null then b when a='' then b else a end from test
复制代码 ,粘贴,执行,直接可以看到结果
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select case when a is null then b when a='' then b else a end from 表
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select case when a is null then b else a end
from 表
from 表
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不同数据库写法不一样
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询