sql中如何再判断一个字段是否为空,如果不为空然后再Select这个字段,这要如何写呢?

比如:
select firstName + lastName from employee
这里我想先判断lastName是否为空,如果为空的话lastName返回指定默认值,不为空就直接返回数据库中的值。

第1个回答  2012-04-12
--MS-SQL SERVER用ISNULL 函数判断
select firstName + ISNULL(lastName,'默认值') from employee
--要注意的是NULL值与任意值相加都为NULL
第2个回答  2012-04-12
select 列名 from 表名 列名 not is null
第3个回答  推荐于2018-05-09
sqlserver吧:
select firstname + isnull(lastname,'xxxx') from employee
或者
select firstname + case when lastname is null then 'xxxx' else lastname end from employee本回答被提问者和网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网