SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Monthname: Is there a bug in this function


Monthname: Is there a bug in this function

Author
Message
brunm
brunm
SSC-Addicted
SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)

Group: General Forum Members
Points: 494 Visits: 4336
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



brunm
brunm
SSC-Addicted
SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)

Group: General Forum Members
Points: 494 Visits: 4336
=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



brunm
brunm
SSC-Addicted
SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)SSC-Addicted (494 reputation)

Group: General Forum Members
Points: 494 Visits: 4336
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



toolman-352714
toolman-352714
Say Hey Kid
Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)

Group: General Forum Members
Points: 673 Visits: 712
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
latingntlman
latingntlman
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1060 Visits: 521
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.
toolman-352714
toolman-352714
Say Hey Kid
Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)Say Hey Kid (673 reputation)

Group: General Forum Members
Points: 673 Visits: 712
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
Sandeep Saretha
Sandeep Saretha
Old Hand
Old Hand (363 reputation)Old Hand (363 reputation)Old Hand (363 reputation)Old Hand (363 reputation)Old Hand (363 reputation)Old Hand (363 reputation)Old Hand (363 reputation)Old Hand (363 reputation)

Group: General Forum Members
Points: 363 Visits: 389
Use

=MonthName(Month(Parameters!DateBegin.Value))
NeddyRock
NeddyRock
Valued Member
Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)Valued Member (68 reputation)

Group: General Forum Members
Points: 68 Visits: 51
=MonthName(Month(Parameters!DateBegin.Value))

This worked for me.

Thanks!

Ned
shree.shirdhone
shree.shirdhone
SSC Rookie
SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)

Group: General Forum Members
Points: 32 Visits: 2
Problem With MonthName(10,True)
So Following is the workaround.


=Switch(Fields!rsmonth.Value=12,"DEC",
Fields!rsmonth.Value <= 0,"")
shree.shirdhone
shree.shirdhone
SSC Rookie
SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)SSC Rookie (32 reputation)

Group: General Forum Members
Points: 32 Visits: 2
=Switch(Fields!rsmonth.Value=12,"DEC",Fields!rsmonth.Value <= 0,"")
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search