CON空空字段 [英] CONCAT'ing NULL fields
本文介绍了CON空空字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含三个字段的表,名字,姓氏和电子邮件。
I have a table with three fields, FirstName, LastName and Email.
以下是一些虚拟数据:
FirstName | LastName | Email
Adam West adam@west.com
Joe Schmoe NULL
现在,如果我愿意:
SELECT CONCAT(FirstName, LastName, Email) as Vitals FROM MEMBERS
Joe的重要内容为空,因为只有一个空字段。您如何克服这种行为?另外,这是MS SQL Server中的默认行为吗?
Vitals for Joe is null, as there is a single null field. How do you overcome this behaviour? Also, is this the default behaviour in MS SQL Server?
推荐答案
尝试
ISNULL(FirstName, '<BlankValue>') -- In SQL Server
IFNULL(Firstname, '<BlankValue>') -- In MySQL
所以,
CONCAT(ISNULL(FirstName,''),ISNULL(LastName,''),ISNULL(Email,'')) -- In SQL Server
CONCAT(IFNULL(FirstName,''),IFNULL(LastName,''),IFNULL(Email,'')) -- In MySQL
将返回相同的没有null问题的东西(以及应该为null的空白字符串)。
would return the same thing without the null issue (and a blank string where nulls should be).
这篇关于CON空空字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文