[英]CASE expression with NULL value
I'm struggling to understand how to check for a null value in a progress case expression. 我很难理解如何在进度案例表达式中检查空值。 I want to see if a column exists and use that, if not use the fallback column.
我想查看列是否存在并使用它,如果不使用回退列。 For example, William in first name would be over written by Bill in fn.special-char.
例如,名字中的威廉将由比尔在fn.special-char中编写。
I've got the following query: 我有以下查询:
SELECT
"PUB"."NAME"."LAST-NAME" as LastName,
CASE fn."SPECIAL-CHAR"
WHEN is null THEN "PUB"."NAME"."FIRST-NAME"
ELSE fn."SPECIAL-CHAR"
END as FirstName
FROM "PUB"."NAME"
LEFT OUTER JOIN "PUB"."DAT-DATA" fn on "PUB"."NAME"."NAME-ID" = fn."DAT-SRC-ID" and 11 = fn."FLD-FIELD-ID"
When I run the query I get: 当我运行查询时,我得到:
ORBC Progress OpenEdge Wire Protocol driver][OPENEDGE]Syntax error SQL statement at or about "is null then "PUB"."NAME"."FIRST-" (10713)
ORBC Progress OpenEdge Wire Protocol驱动程序] [OPENEDGE]语法错误SQL语句处于或关于“is null然后”PUB“。”NAME“。”FIRST-“(10713)
If I do a select * I see everything. 如果我选择*我会看到一切。 It just doesn't like the null part.
它只是不喜欢null部分。 I can also change the when is null to when 'bob' and it works.
我也可以将when为null时更改为'bob'并且它有效。
Is there something different I need to do to use a null value in a progress db query? 在进度数据库查询中使用空值是否需要做些什么?
The shorthand variation of the case
statement ( case expression when value then result ...
) is a shorthand for a series of equality conditions between the expression and the given values. case
语句的简写变体( case expression when value then result ...
)是表达式和给定值之间的一系列相等条件的简写。 null
, however, is not a value - it's the lack thereof, and must be evaluated explicitly with the is
operator, as you tried to do. 但是,
null
不是一个值 - 它是缺少的,并且必须使用is
运算符显式计算,正如您尝试的那样。 In order to do this properly, however, you need to use a slightly longer variation of the case
syntax - case when condition then result ...
: 但是,为了正确地执行此操作,您需要使用
case
语法稍微更长的变体 - case when condition then result ...
:
SELECT
"PUB"."NAME"."LAST-NAME" as LastName,
CASE WHEN fn."SPECIAL-CHAR" IS NULL THEN "PUB"."NAME"."FIRST-NAME"
ELSE fn."SPECIAL-CHAR"
END as FirstName
FROM "PUB"."NAME"
LEFT OUTER JOIN "PUB"."DAT-DATA" fn on "PUB"."NAME"."NAME-ID" = fn."DAT-SRC-ID" and 11 = fn."FLD-FIELD-ID"
Instead of CASE
you can use IFNULL function in Progress 4GL. 您可以在Progress 4GL中使用IFNULL函数代替
CASE
。
SELECT
"PUB"."NAME"."LAST-NAME" as LastName,
IFNULL(fn."SPECIAL-CHAR", "PUB"."NAME"."FIRST-NAME") as FirstName
FROM "PUB"."NAME"
LEFT OUTER JOIN "PUB"."DAT-DATA" fn on "PUB"."NAME"."NAME-ID" = fn."DAT-SRC-ID" and 11 = fn."FLD-FIELD-ID"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.