SSRS表达式评估问题

发布于 2024-07-09 06:13:01 字数 954 浏览 7 评论 0原文

我对报告中的表达式有疑问。 我根据表中的值对表中文本框的背景进行着色。 该字段中的文本与 SQL Server 的备份相关。 该值可以是日期或文本“尚未采取”。 如果日期超过 2 天,我希望背景为黄色。 如果它已经超过一周或日期值为“尚未采取”,我希望背景为红色。 不然就绿了。

自从我开始使用 SSRS 报告(几周前)以来,我一直遇到的问题是我的表达式似乎得到了充分评估。 IF 语句将同时评估其 true 和 false 值,即使仅使用其中之一。

这成为一个问题,因为“尚未采取”显然不是日期,并且要使用日期,我需要将日期字符串转换为日期。 这是我当前的代码:

=IIF(Fields!LastBackUpTaken.Value = "Not Yet Taken","Red", IIF( IsDate(Fields!LastBackUpTaken.Value) = true,
  IIF( CDate(Fields!LastBackUpTaken.Value).AddDays(Parameters!DaysTillExpiry.Value).CompareTo(NOW()) = 1,
          "GreenYellow",
      IIF( CDate(Fields!LastBackUpTaken.Value).AddDays(7).CompareTo(NOW()) = 1, "Yellow", "Red")),
  "Red"))

所以基本上,表达式读取“If LastBackUpTaken.Value =”Not Yet Taken“,返回颜色红色。如果它不是“Not Yet Taken”,请检查字符串是否是如果不是日期,则返回红色。如果是日期,则执行计算并返回适当的颜色。

此表达式适用于所有不包含“尚未采用”文本的文本字段。对于确实有“尚未采取”的字段,因为其文本没有任何颜色设置

编辑:每当文本为“尚未采取”时,我也会收到一个我忘记提及的转换错误

有什么想法吗?

I'm having an issue with expressions within reports. I'm coloring the background of a textbox within a table depending on the value within it. The text in the field relates to backups for a SQL Server. The value is either a date or the text "Not Yet Taken". If the date is more than 2 days old, I want the background to be yellow. If its more than a week old or if the date value is "Not Yet Taken", I want the background to be red. Otherwise, it'll be green.

The problem I've been having since I started with reports for SSRS (a few weeks ago) is that my expressions seem to get fully evaluated. An IF statement will have both its true and false values evaluated even though only one of them will be used.

This becomes a problem because "Not Yet Taken" is clearly not a date and to work with the dates I need to convert the date string into a date. Here is the code I have currently:

=IIF(Fields!LastBackUpTaken.Value = "Not Yet Taken","Red", IIF( IsDate(Fields!LastBackUpTaken.Value) = true,
  IIF( CDate(Fields!LastBackUpTaken.Value).AddDays(Parameters!DaysTillExpiry.Value).CompareTo(NOW()) = 1,
          "GreenYellow",
      IIF( CDate(Fields!LastBackUpTaken.Value).AddDays(7).CompareTo(NOW()) = 1, "Yellow", "Red")),
  "Red"))

So basically, the expression reads "If LastBackUpTaken.Value = "Not Yet Taken", return the color Red. If it isn't "Not Yet Taken", check to see if the string is a date. If it isn't a date, return the color Red. If it is a date do calculations and return the appropriate color.

This expressions works for all the text fields that don't have "Not Yet Taken" as its text. For the fields that do have "Not Yet Taken" as its text do not have any color set.

EDIT: I also get a conversion error that I forgot to mention, whenever the text is "Not Yet Taken"

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夕嗳→ 2024-07-16 06:13:01

编写一个 VB 函数以返回“报告属性”的“代码”选项卡中的颜色字符串。 在这里,您可以使用您熟悉的语言结构(case 语句、常规 if 语句等)。 逻辑也更容易回读。

Public Function GetBackgroundColor(ByVal DateString as String) As String
    'plain old vb syntax here
End Function

在背景颜色属性的表达式中:

=Code.GetBackgroundColor(Fields!LastBackUpTaken.Value)

Write a VB function to return the color string in the Code Tab of the Report Properties. Here you can use language constructs you are comfortable with (case statements, regular if statements, etc.). Logic with be easier to read back as well.

Public Function GetBackgroundColor(ByVal DateString as String) As String
    'plain old vb syntax here
End Function

In the expression for the background color property:

=Code.GetBackgroundColor(Fields!LastBackUpTaken.Value)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文