all groups > sql server reporting services > october 2006 >
You're in the

sql server reporting services

group:

Formating a numeric string, that is sometimes text


Formating a numeric string, that is sometimes text msflinx
10/20/2006 11:30:02 AM
sql server reporting services:
The old string didn't move up when I replied to it, so copied the information
into this new question
---------------------------------------------------------------------------------

OK -- this works to a point. I have real string data in my field that I want
to display, if the field is not "isnumeric". So, here is the code I am using:

=iif(isnumeric(Fields!Q4Amt.Value),
Format(convert.ToDouble(Fields!Q4Amt.Value),
"$###,###,##0.00;($###,###,##0.00);$0.00"), "N/A")

Every time the N/A is supposed to be displayed, I get an error message.

Thanks for any and all help

[quoted text, click to view]
Re: Formating a numeric string, that is sometimes text msflinx
10/20/2006 12:40:02 PM
Thank you Michael. Didn't quite do to trick, but put me in the right
direction.

This is the code I ended up with in the Report Property's Code Tab:

Public Function NumericStringToCurrencyString(ByVal strPhrase as string) as
string

if isnumeric(strPhrase) then
NumericStringToCurrencyString =
format(cdec(strPhrase),"$###,###,###.##;($###,###,###.##);$0.00")
else
NumericStringToCurrencyString = strPhrase
end if

end function

Then I called it like you wrote in the field and Viola!!! It worked.

Thank you ever so much.

[quoted text, click to view]
Re: Formating a numeric string, that is sometimes text Michael Abair
10/20/2006 3:16:26 PM
This will happen because of the nature of IIF. IIF calculates both the true
and false values before choosing which one to display. So it actually is
failing because in the background it trys to convert the string to a double
and return the value. Writing Custom Code to take advantage of the real IF
function is a way around this.
If you know VB its pretty simple.
report->report properties-> code tab->


Public Function checkstr(ByVal testval As String)
IF Char.IsNumber(testval, 0) THEN
return CDbl(testval)
ELSE
return "N/A"
END IF
End Function

Then apply the formatting in the textbox you want N/A Displayed in and have
your text box state the following
=Code.checkstr(Fields!Q4Amt.Value)
-Michael Abair

Programmer Analyst

Chicos FAS Inc.



[quoted text, click to view]

Re: Formating a numeric string, that is sometimes text Chris Conner
10/20/2006 3:23:14 PM
I like your solution better than mine Michael... kudos! :)

=-Chris

[quoted text, click to view]

Re: Formating a numeric string, that is sometimes text Chris Conner
10/20/2006 3:43:25 PM
You know, it never even occured to me that the logical IIF would do that...
that is evaluate the expression, and the false case...

i.e.

if a = 5 then is this fine...

=iif(IsNumeric(a), Format(Convert.ToDouble(a), "#"), "N/A")

if a = 'test' I would expect "N/A" to print out...

Of course I HAD to create a report to test it... and sure enough, it broke
the moment I put a text character in instead of a value.

Thanks for the great tip.

=-Chris

[quoted text, click to view]

Re: Formating a numeric string, that is sometimes text Michael Abair
10/20/2006 3:49:31 PM
Much Appreciated!

[quoted text, click to view]

AddThis Social Bookmark Button