Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Monthname: Is there a bug in this function Expand / Collapse
Author
Message
Posted Tuesday, September 2, 2008 5:08 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, September 29, 2014 6:57 AM
Points: 185, Visits: 4,334
Can someone tell me if there is a bug/issue with the SSRS built in function MonthName

The following expression in the header of my report returns an error on the True Part, but not on the false part

IIF(Parameters!THE_MONTH.Value = 100," Year " , cstr(monthname(Parameters!THE_MONTH.Value)))


Basically i have a drill through report based on Months but with a total for which i pass the month in as 100



Post #562311
Posted Tuesday, September 2, 2008 5:21 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, September 29, 2014 6:57 AM
Points: 185, Visits: 4,334
=IIF(cint(Parameters!THE_MONTH.Value) = 100, monthname(1) , monthname(Parameters!THE_MONTH.Value))


This also returns #error when Parameters!THE_MONTH.Value = 100, however if Parameters!THE_MONTH.Value is for example 10 'October' is returned

This does not make any sense



Post #562314
Posted Tuesday, September 2, 2008 5:39 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, September 29, 2014 6:57 AM
Points: 185, Visits: 4,334
I have figured out how to do it using a work around.

it seems it must evaluate the expression from right to left

if i include a second Parameter called Month_NAME2 and set its default as

=IIF(Parameters!THE_MONTH.Value = 100,1,Parameters!THE_MONTH.Value)

Then my text box will look at MONTH_NAME2 which will either be 1-12 or 1


Work Around and SSRS seem to be 2 statements that go hand in hand



Post #562319
Posted Tuesday, September 2, 2008 9:54 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, July 15, 2013 1:11 PM
Points: 138, Visits: 698
What you've run into is not necessarily an SSRS issue although it manifests itself there a lot. Especially when using IIF to catch divide by zero conditions.
The problem is with the IIF function in VB.net.
In BOL, under Visual Basic Language Reference - IIf Function
(http://msdn.microsoft.com/en-us/library/27ydhh0d(VS.71).aspx)
it offers the following remark,
"The expressions in the argument list can include function calls. As part of preparing the argument list for the call to IIf, the Visual Basic compiler calls every function in every expression. This means that you cannot rely on a particular function not being called if the other argument is selected by Expression."

So...what's happening is, regardless of your trying to condition away the erroneous 'MONTHNAME(100)' condition, the compiler still sees it and throws the #error.

The two most common workarounds are to either write a custom code function that accomplishes your end and then use it instead of the IIF or use a nested IIF in your 'false' condition. This second option works because the compiler does read from the most nested conditions outward.

Given what you're trying to accomplish, I suggest a third option. try using the SWITCH() function. If you go to the link above, a link for SWITCH can be found at the bottom under See Also.

HTH


toolman
Numbers 6:24-26
Post #562486
Posted Wednesday, October 29, 2008 12:01 PM


SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Today @ 12:45 PM
Points: 206, Visits: 452
I, too, am getting #Error when running my report. I'm trying to get the name of the month and year to display in my header. The year part works, but somehow the MonthName function is not working.

=MonthName(Parameters!DateBegin.Value)

Is there a diff function I should be using?

thx.
Post #593843
Posted Wednesday, October 29, 2008 1:01 PM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, July 15, 2013 1:11 PM
Points: 138, Visits: 698
latingntlman (10/29/2008)
I, too, am getting #Error when running my report. I'm trying to get the name of the month and year to display in my header. The year part works, but somehow the MonthName function is not working.

=MonthName(Parameters!DateBegin.Value)

Is there a diff function I should be using?

thx.


Take a look here to see if it gives you any clues.
http://msdn.microsoft.com/en-us/library/zxbsw165(VS.71).aspx
Another thought is you may need to break down your date value into month and year. Something like:
=MonthName(Month(Parameters!DateBegin.Value))
HTH


toolman
Numbers 6:24-26
Post #593879
Posted Friday, April 10, 2009 12:38 PM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, September 16, 2014 12:59 PM
Points: 287, Visits: 386
Use

=MonthName(Month(Parameters!DateBegin.Value))
Post #695031
Posted Wednesday, March 31, 2010 3:18 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, March 23, 2012 10:11 AM
Points: 6, Visits: 49
=MonthName(Month(Parameters!DateBegin.Value))

This worked for me.

Thanks!

Ned
Post #894240
Posted Wednesday, May 8, 2013 3:18 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, May 8, 2013 3:19 AM
Points: 2, Visits: 2
Problem With MonthName(10,True)
So Following is the workaround.


=Switch(Fields!rsmonth.Value=12,"DEC",
Fields!rsmonth.Value <= 0,"")
Post #1450464
Posted Wednesday, May 8, 2013 3:19 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, May 8, 2013 3:19 AM
Points: 2, Visits: 2
=Switch(Fields!rsmonth.Value=12,"DEC",Fields!rsmonth.Value <= 0,"")
Post #1450465
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse