Groups | Blog | Home
all groups > sql server reporting services > february 2005 >

sql server reporting services : Formating for a phone number


ReportDude
2/23/2005 1:25:04 PM
I have a report in which I'd like to display a phone number.

Currrently, in SQL Server, the phone numbers appear as a string a numbers eg
"4255551212"

I'd like to display them with area code, then number such as "(425) 555-1212"

I've tried playing aroud with formating options and I'm stumped...
ReportDude
2/23/2005 2:17:05 PM
I get an error that says "There is an error on line 5 of custom code:
Expression Expected"

I don't understand this - the code does have an expression...

any ideas?

[quoted text, click to view]
andrei
2/23/2005 4:35:21 PM
Hi, ReportDude,

Try

=Format(CDbl("4255551212"), "(000) 000-0000")

HTH,

Andrei.



[quoted text, click to view]

Christopher Conner
2/23/2005 4:48:34 PM
Create a function i.e. and put it in the code tab section under report
properties.

public function FormatNumber(StrPhone as String) as String
dim sRetString as String = ""
if IsNothing(StrPhone)
sRetString = ""
else
sRetString = "(" & StrPhone.SubString(0, 2) & ") " &
StrPhone.SubString(3,3) & "-" & StrPhone.SubString(6,4)
end if
return sRetString
end function

Then in your grid, lets say... for the expression of the text control...

Code.FormatNumber(Fields!Phone.Value)

Now the code I just gave you might have bugs in it - as I am in a hurry :)
So test it and correct where needed - but you get the idea.

=-Chris

[quoted text, click to view]

Christopher Conner
2/23/2005 6:13:54 PM
That is because of a line break in the code... I have recopied it from dev
studio, copy this and paste it into the code block between the function name
and end function...

Dim sRetString As String = ""

If IsNothing(StrPhone) Then

sRetString = ""

Else

sRetString = "(" & StrPhone.Substring(0, 2) & ") " & StrPhone.Substring(3,
3) & "-" & StrPhone.Substring(6, 4)

End If

Return sRetString



[quoted text, click to view]

AddThis Social Bookmark Button