简体   繁体   English

SSRS 2008R2表达式以限制文本

[英]SSRS 2008R2 Expression to limit text

I have a tabular report that pulls in a field that shows free text. 我有一个表格报告,其中会显示一个显示自由文本的字段。 By adding: 通过增加:

=Left(fields!data.value,250) I can limit the number of characters to 250. However what I would really like to do is end the text after the last full stop (period) closest to 250 characters. = Left(fields!data.value,250)我可以将字符数限制为250。但是,我真正想做的是在最后一个句点(句点)之后最接近250个字符的地方结束文本。

Eg, at the moment the report may display: 'Sales reached 25,000 for September. 例如,目前报告可能显示:“ 9月份的销售额达到25,000。 We are planning' and end abruptly at 'planning' as 'planning'is where 250 characters end. 我们正在计划”,并突然终止于“计划”,因为“计划”是250个字符的结尾。

Ideally I would like the text to end at the end of the sentence before, eg to stop after 'September'. 理想情况下,我希望文本在句子的结尾处结束,例如在“ 9月”之后停止。

Do you know if this is possible - any suggestions or pointers would be hugely appreciated. 您知道这是否可行吗?任何建议或指示将不胜感激。

With many thanks. 非常感谢。

You can use InStrRev to get the last period in the string, and use this as a parameter for the Left expression. 您可以使用InStrRev获取字符串中的最后一个句点,并将其用作Left表达式的参数。

There are also a few more checks to consider, such as: 还需要考虑其他一些检查,例如:

  • When there are no periods in the string 当字符串中没有句点时
  • When there are no periods in the first 250 characters 前250个字符中没有句点时
  • When there are periods after the 250 character cut off as well as periods in the first 250 characters. 截断250个字符后的句点以及前250个字符中的句点。

This should work and catch most of the exceptions I can think of: 这应该起作用并捕获我能想到的大多数异常:

=IIf(InStrRev(Left(Fields!data.Value, 250), ".") > 0
        And InStrRev(Left(Fields!data.Value, 250), ".") <= 250
    , Left(Fields!data.Value, InStrRev(Left(Fields!data.Value, 250), "."))
    , Left(Fields!data.Value, 250))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM