SSRS IIF Date evaluation

这一生的挚爱 提交于 2019-12-06 08:25:57

问题


I have the following code

=IIf(Fields!Freeze.Value, Fields!effectivedate.Value, IIF(Month(Fields!effectivedate.Value) <> Month(Now()), Format(Now(), “MM/dd/yyyy”) , Fields!effectivedate.Value))

A. In the first IIF statement I check to see if the Fields!Freeze.Value is true, if its true then It displays Fields!effectivedate.Value (IIf(Fields!Freeze.Value, Fields!effectivedate.Value)

B. In the second IIF statemenet I check if the Fields!effectivedate.Value is the current month, If it is the current month then it displays Fields!effectivedate.Value, If it is not the current month then it displays the current date.

I would like assistance on the following.

In the first IIF statement ,>>> IIf(Fields!Freeze.Value, Fields!effectivedate.Value, I want to evaluate a new value Fields!FreezeDate.value

  1. If the Fields!Freeze.Value = true then check to see if the Fields!effectivedate.Value is 30 days or more less than Fields!FreezeDate.value. A. If its 29 days or less than Fields!FreezeDate.value then display Fields!effectivedate.Value B. If its 30 days or more less than the Fields!FreezeDate.value then display the Fields!FreezeDate.value

Example 1

 Fields!FreezeDate.value  = '12/30/2012'
 Fields!effectivedate.Value = '11/15/2010'


 then Display the Fields!FreezeDate.value

Example 2

 Fields!FreezeDate.value  = '12/30/2012'
 Fields!effectivedate.Value = '12/15/2010'


 then Display the Fields!effectivedate.Value

How would I write this in SSRS code?

Please ask for further clarification if i have failed to explain something properly.


回答1:


As I understand the requirement, you'll need to add another IIf() section which checks the difference in days between the two dates, then displays effectiveDate if the difference is < 30 days:

=IIf
(
  Fields!Freeze.Value
  , IIF
  (
    DateDiff(DateInterval.Day, Fields!effectiveDate.Value, Fields!FreezeDate.Value) < 30
    , Fields!effectiveDate.Value
    , Fields!FreezeDate.Value
  )
  , IIF
  (
    Month(Fields!effectivedate.Value) <> Month(Now())
    , Format(Now(), “MM/dd/yyyy”)
    , Fields!effectivedate.Value
  )
)



回答2:


I suspect the thing you're missing is knowledge of the DATEDIFF function.

http://msdn.microsoft.com/en-us/library/aa337092%28v=sql.90%29.aspx

IIF(
  DATEDIFF(DAY, Fields!FreezeDate.Value, Fields!effectiveDate.Value) => 30,
  Fields!FreezeDate.Value, 
  Fields!effectiveDate.Value )

Above, we're using DATEDIFF.

First parameter is the Time measurement we want to measure differences between. DAY.

Example:-

DATEDIFF(DAY, '2013-01-01', '2013-01-15') should yield 14.

Tying it all up, we're calculating the day difference between FreezeDate and effectiveDate. When that value is over 30, display the effectiveDate. Otherwise, display FreezeDate.

You may need to play around to get the desired result. Your English description of your logic was not great. Did the best I could under the circumstances.



来源:https://stackoverflow.com/questions/14197057/ssrs-iif-date-evaluation

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