[英]SQL view with calculated column type becomes nullable
I have got a sql table view where one of the columns is calculated: 0.1 * [column_name]
where [column_name]
is of type Decimal
not NULL
. 我有一个sql表格视图,其中计算列之一:
0.1 * [column_name]
其中[column_name]
的类型为Decimal
而不是NULL
。
Received view field becomes Decimal NULL
because of some reason. 由于某种原因,接收到的视图字段变为
Decimal NULL
。
Why NOT NULL
changes to NULL
? 为什么
NOT NULL
变为NULL
?
Regards Mariusz 问候马吕斯
You can force it back to being not null by wrapping it in an ISNULL: 您可以通过将其包装在ISNULL中来强制其返回非null值:
create table T (
Value decimal(38,12) not null
)
go
create view V1
as
select 0.1 * Value as Value from T
go
create view V2
as
select ISNULL(0.1 * Value,0) as Value from T
go
V1's value column is marked as nullable, V2's isn't. V1的值列标记为可为空,而V2则不是。 Strangely, this is one place where you can't use the more standards compliant
COALESCE
: 奇怪的是,这是您无法使用更符合标准的
COALESCE
:
create view V3
as
select COALESCE(0.1 * Value,0) as Value from T
go
V3 resembles V1. V3与V1类似。
您忘记了发布代码,但这可能是因为左联接或右联接找不到匹配的行...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.