SSRS Date evaluation problem

Posted on 2013-01-07
Medium Priority
Last Modified: 2013-01-07
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/2012'

     then Display the Fields!FreezeDate.value

Example 2

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

     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.
Question by:michiganblkman
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 37

Expert Comment

ID: 38750844
You can use the DateDiff function to get the difference between two dates.  Have a look at the following expression:

=DateDiff(DateInterval.Day, CDate("2012-12-30"), CDate("2012-11-15"))

That would return the difference, in days, between those two dates. Because the first one is later than the second one the result, -45, is negative.

The above should give you something to get started with your expression enhancement.


Author Comment

ID: 38751286
yes ValentinoV,

I have so far DateDiff(DateInterval.Day, Fields!effectiveDate.Value, Fields!FreezeDate.Value) < 30
    , Fields!effectiveDate.Value
    , Fields!FreezeDate.Value

Because this is a paid forum, I didnt think I would be out of line to ask for an answer outright.

I am interested in seeing how others would tackle this problem.
LVL 37

Accepted Solution

ValentinoV earned 2000 total points
ID: 38751993
Who said something about being out of line?  I surely didn't?  But it's not because it's a paid forum that you should expect others to do your work for you.  That's what they've invented consultancy for.  Besides, it might be a paid forum but the experts here are all volunteers who just like doing this stuff.  Or in other words: it doesn't hurt to think a bit as well, you might learn something while at it.  Don't worry though, we've all got the same goal in mind: to help you solve your issue!

The expression you posted will work as long as effective date is always smaller (earlier) than freeze date, is that the case?  If yes, in full your expression would become something like this:

	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))

Open in new window


Author Comment

ID: 38752191
Thanks for your view on things.  FYI, I have been a member here since 2002 back when it was free.  Since 2004 i have been a paid member. In that time i have asked 16 questions. I havent done the math on what over 8 years of membership fees/16 questions ratio is.  So I guess I would hardly consider myself a person that "gets others to do the work for me" since i have only presented 16 questions to this forum since 2002.     I only ask here when I truly dont have time to figure something out.  

Thanks for your answer.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question