0

In sql server, I see a strange behaviour: When I do

select col1+ ' ' + cast(col2 as varchar(10)) as concat_col

it returns me a column with a value = NULL (not a blank column).

My suspicion is that it is because col2 has a value = NULL (not blank column). So what is the reason for this behavior? But more importantly, what is the meaning of a column with value = NULL as opposed to a blank column? I do not imagine somebody went in the table and updated all the columns with value = NULL.

4

2 回答 2

1

NULL 表示该字段没有任何值。您可以使用 ISNULL 函数将空值转换为您想要的值。以下内容有望为您提供正确的结果(不会给出空值)

select ISNULL(col1,'')+ ' ' + cast(ISNULL(col2,'') as varchar(10)) as concat_col
于 2012-08-29T23:32:33.187 回答
0

空白是一个值,而 null 完全没有。

认为零是一个数字,而 null 什么都不是。

于 2012-08-29T23:34:37.820 回答