SSRS trouble using DateDiff in a IIF statement

老子叫甜甜 提交于 2019-12-10 19:17:55

问题


SSRS returns an #error when the statement is False, but No Start Date when the statement is True. I tested and the DateDiff is correct in the False side of the statement. I'm not sure which direction to go from here. Thank you.

=IIF(Fields!JobOrderIssueDate.Value = "", "No Start Date",DateDiff("d",Today(),Fields!ProjectedConstEndDate.Value))

回答1:


You are mixing data types in your IIF returning either a STRING or a DATE depending on the condition of the IIF. This is not going to work.

One approach would be to convert the data type returned by the FALSE condition so that it is also returns a STRING (using CStr()):

=IIF(Fields!JobOrderIssueDate.Value = "", "No Start Date",CStr( DateDiff("d",Today(),Fields!ProjectedConstEndDate.Value)))

or you could gain a little more control over formatting (using FormatDateTime()):

=IIF(Fields!JobOrderIssueDate.Value = "", "No Start Date",FormatDateTime( DateDiff("d",Today(),Fields!ProjectedConstEndDate.Value), DateFormat.ShortDate)) 



回答2:


Change format to compare between data and string also will not work, the best method to inspect the Date field with IsDate function

=IIF(IsDate(Fields!JobOrderIssueDate.Value), DateDiff("d",Today(),Fields!ProjectedConstEndDate.Value), "No Start Date")


来源:https://stackoverflow.com/questions/34276247/ssrs-trouble-using-datediff-in-a-iif-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!