让 Crystal Reports 公式将数字字符串转换为值,但将非数字留空/空 [英] Have a Crystal Reports formula convert numeric strings to values, but leave non-numeric blank/null

查看:14
本文介绍了让 Crystal Reports 公式将数字字符串转换为值,但将非数字留空/空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串字段,该字段主要包含十进制数值,但有时包含诸如<0.10"或HEMOLYSIS"之类的值.

I have a string field that mostly contains numeric decimal values, but sometimes contains values like "<0.10" or "HEMOLYSIS".

我想使用公式将这些数值字符串转换为值,将非值留空(null).

I want to use a formula to convert these numeric value strings to values, leaving non-values blank (null).

if isNumeric({a_omgang.omg_resultat}) then
    toNumber({a_omgang.omg_resultat})

为所有非数字值返回 0,这使得计算变得困难,例如平均值或平均值,或计算值的数量.(后者当然可以通过使用带有 isNumeric 评估公式的运行总数来实现.)

returns 0 for all non-numeric values, which makes it hard to calculate e.g. average or mean, or to count the number of values. (The latter can of course be achieved by using a running total count with isNumeric evaluation formula.)

有什么建议可以让公式按我的意愿工作吗?

Any suggestions how I can get the formula to work as I want?

我希望该值为空白(null),而不仅仅是非数字的可见性.

I want the value to be blank (null), not just turn of visibility if non-numeric.

推荐答案

过去,我创建了一个返回 NULL 的 SQL 表达式:

In the past, I've created a SQL Expression that returns a NULL:

-- {@DB_NULL}
-- Oracle syntax
(
SELECT NULL FROM DUAL
)

 

-- {@DB_NULL}
-- MS SQL syntax
(
SELECT NULL
)

然后我在公式中引用这个字段:

Then I reference this field in the formula:

// {@FormulaField}
If IsNumberic({table.field} Then
  ToNumber({table.field})
Else
  ToNumber({@DB_NULL})

这篇关于让 Crystal Reports 公式将数字字符串转换为值,但将非数字留空/空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆