SQL Server String Concatenation with Null(SQL Server 字符串与 Null 的连接)
问题描述
我正在跨字段创建一个计算列,其中一些字段可能为空.
I am creating a computed column across fields of which some are potentially null.
问题在于,如果这些字段中的任何一个为空,则整个计算列将为空.我从 Microsoft 文档中了解到这是预期的并且可以通过设置 SET CONCAT_NULL_YIELDS_NULL 关闭.但是,我不想更改此默认行为,因为我不知道它对 SQL Server 其他部分的影响.
The problem is that if any of those fields is null, the entire computed column will be null. I understand from the Microsoft documentation that this is expected and can be turned off via the setting SET CONCAT_NULL_YIELDS_NULL. However, there I don't want to change this default behavior because I don't know its implications on other parts of SQL Server.
有没有办法让我只检查一列是否为空,并且只在计算列公式中附加它的内容,如果它不为空?
Is there a way for me to just check if a column is null and only append its contents within the computed column formula if its not null?
推荐答案
您可以使用 ISNULL(....)
SET @Concatenated = ISNULL(@Column1, '') + ISNULL(@Column2, '')
如果列/表达式的值确实为 NULL,则将使用指定的第二个值(此处:空字符串).
If the value of the column/expression is indeed NULL, then the second value specified (here: empty string) will be used instead.
这篇关于SQL Server 字符串与 Null 的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQL Server 字符串与 Null 的连接


基础教程推荐
- 如何在 SQL 中将 Float 转换为 Varchar 2021-01-01
- 什么是 orradiag_<user>文件夹? 2022-01-01
- 如何根据该 XML 中的值更新 SQL 中的 XML 2021-01-01
- mysql选择动态行值作为列名,另一列作为值 2021-01-01
- MySQL 中的类型:BigInt(20) 与 Int(20) 2021-01-01
- 在 MySQL 中:如何将表名作为存储过程和/或函数参数传递? 2021-01-01
- 在多列上分布任意行 2021-01-01
- 表 './mysql/proc' 被标记为崩溃,应该修复 2022-01-01
- 二进制文件到 SQL 数据库 Apache Camel 2021-01-01
- oracle区分大小写的原因? 2021-01-01