水晶报表公式:IsNull + 伊夫
这个网站上到处都有这个问题答案的提示,但我问的问题略有不同。
Crystal Reports 在哪里记录了此语法不起作用?
Trim({PatientProfile.First}) + " "
+ Trim(Iif(
IsNull({PatientProfile.Middle})
, Trim({PatientProfile.Middle}) + " "
, " "
)
)
+ Trim({PatientProfile.Last})
我知道解决方案是,
If IsNull({PatientProfile.Middle}) Then
Trim({PatientProfile.First})
+ " " + Trim({PatientProfile.Last})
Else
Trim({PatientProfile.First})
+ " " + Trim({PatientProfile.Middle})
+ " " + Trim({PatientProfile.Last})
但我们如何知道我们不能使用第一个版本?
IsNull 的文档说
- 评估当前记录中指定的字段,如果该字段包含空值
,则返回 TRUE,如果表达式为 True,则 Iif 给出
- [Returns] truePart;如果表达式为 False,则 Iif 给出 [Returns] truePart。 返回值的类型与truePart和falsePart的类型相同。
我想如果你盯着关于“返回值类型”的那一行你就可以明白,但是......
There are hints of the answer to this question here and there on this site, but I'm asking a slightly different question.
Where does Crystal Reports document that this syntax does not work?
Trim({PatientProfile.First}) + " "
+ Trim(Iif(
IsNull({PatientProfile.Middle})
, Trim({PatientProfile.Middle}) + " "
, " "
)
)
+ Trim({PatientProfile.Last})
I know the solution is
If IsNull({PatientProfile.Middle}) Then
Trim({PatientProfile.First})
+ " " + Trim({PatientProfile.Last})
Else
Trim({PatientProfile.First})
+ " " + Trim({PatientProfile.Middle})
+ " " + Trim({PatientProfile.Last})
but how are we supposed to figure out we can't use the first version?
The documentation for IsNull says
- Evaluates the field specified in the current record and returns TRUE if the field contains a null value
and Iif gives
- [Returns] truePart if expression is True and falsePart if expression is False. The type of the returned value is the same as the type of truePart and falsePart.
I suppose if you stare at that line about "type of the return value" you can get it, but...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我怀疑整个宇宙中是否有足够大的地方来记录水晶报表中不起作用的所有内容......
I doubt there is anyplace large enough in the entire universe to document everything that does not work in Crystal Reports...
我知道我在这个问题上迟到了好几年,但我在试图弄清楚同样的事情时遇到了这个问题。 有趣的是,我什至无法在 Crystal Reports 文档中找到答案,而是在 链接中找到IBM。
一般来说,如果您使用 Crystal Reports 8.x 或 10.x,
ISNULL
和IIF
不能一起工作。 从网站:如果您使用 CR 8.x 或 10.x(我们就是),那么您就不走运了。 当您将多个字段连接在一起并且其中一个字段可能为 NULL 时,这会变得非常有趣。
I know I'm years late on this one, but I came upon this question while trying to figure out the same thing. Funny enough, I couldn't even find the answer in Crystal Reports documentation, but instead in a link to IBM.
Baiscally, if you're using Crystal Reports 8.x or 10.x,
ISNULL
andIIF
don't work together. From the site:So if you're using CR 8.x or 10.x (which we are), you're out of luck. It makes it REAL fun when you are concatenating multiple fields together and one of them might be NULL.
我认为 CR 评估 IIF 的正确部分和错误部分。 因为你有“Trim({PatientProfile.Middle})”部分,它将根据空值进行评估,CR 公式计算器似乎失败了。
I think CR evaluates both IIFs true and false parts. Because you have "Trim({PatientProfile.Middle})" part there, which will be evaluated aganst null value, CR formula evaluator seems just fail.
尝试这个:
try this: