简体   繁体   English

错误时评估SSRS表达式

[英]SSRS Expression Evaluated When False

In an SSRS report I have a field that has an expression that takes a name in "LastName, FirstName" format and puts it into "FirstInitial. LastName" if it contains a comma (this part always works). 在SSRS报告中,我有一个字段,该字段的表达式名称为“ LastName,FirstName”格式,如果包含逗号,则将其置于“ FirstInitial。LastName”(此部分始终有效)。 However, if the string does not contain a comma, it should just print the string, but instead the report displays "#Error": 但是,如果该字符串不包含逗号,则应仅打印该字符串,而报告将显示“ #Error”:

=IIF(InStr(Fields!EmployeeName.Value, ", ") > 0, Mid(Fields!EmployeeName.Value, Instr(Fields!EmployeeName.Value, " ") + 1, 1) & ". " & Mid(Fields!EmployeeName.Value, 1, Instr(Fields!EmployeeName.Value, ",") - 1), Fields!EmployeeName.Value)

The weird part is that if I change the "true" logic to just have it print the string "contains comma", this expression works exactly as expected - a string of "LastNameOnly" produces "LastNameOnly" and the others print "contains comma". 奇怪的是,如果我更改“ true”逻辑以使其仅打印字符串“ contains comma”,则此表达式将按预期方式工作-字符串“ LastNameOnly”将生成“ LastNameOnly”,其他字符串将显示“ contains逗号” 。 So it seems that even though the statement is false, it's still running the string through the "true" logic, despite it not being used, and throws an error. 因此,即使该语句为假,它似乎仍在通过“ true”逻辑运行该字符串,尽管该字符串未被使用,但会引发错误。

I've tried having the string modifier be in the true and the false sections (and adjusting the evaluation statement accordingly) of the if statement and that doesn't seem to make a difference. 我尝试过将string修饰符放在if语句的true和false部分(并相应地调整评估语句)中,这似乎没有什么区别。

Has anyone ran into this / have a solution? 有没有人遇到这个/有解决方案? Or maybe I'm missing something?? 还是我想念什么? Thanks in advance! 提前致谢!

Using SQL Server 2008, developing in BIDS extension for Visual Studio 2013 使用SQL Server 2008在Visual Studio 2013的BIDS扩展中开发

Apparently SSRS evaluates both the true and false conditions, regardless of which one it's going to use. 显然,SSRS会评估真假条件,而不管它要使用哪种条件。 The work around for this is to use VB custom code. 解决方法是使用VB自定义代码。 Here is a link that shows you how to use VB in SSRS 这是一个链接,向您展示如何在SSRS中使用VB

http://dyslexicanaboko.blogspot.com/2012/11/ssrs-logical-flaws-of-iif.html http://dyslexicanaboko.blogspot.com/2012/11/ssrs-logical-flaws-of-iif.html

Hope this helps others! 希望这对别人有帮助!

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

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