Jonathan Porter
Jonathan Porter

Reputation: 1556

How to custom format a string in SSRS

I'm experimenting with custom formatting of strings and I wrote a simple function to do this task as shown below.

Function written inside the "Code" pane of the report properties:

Function FormatProject(Project AS String) AS String
    IF (Project Is Nothing) Then
        Return Nothing
    Else
        Return Format(Project, "## #####")
    End If
End Function

Input: PR12345

Expected Output: PR 12345

Actual Output: ## #####

I'm using the hash signs because I wrote a similar function to customize a phone number and it worked for that but perhaps it only works with numeric data types and I might need to use a different placeholder.

Thank you in advance!

Upvotes: 0

Views: 157

Answers (1)

NoAlias
NoAlias

Reputation: 9193

You can use the Left and Mid functions to help here (I imagine Substring is supported too):

Return Left(Project, 2) & " " & Mid(Project, 3, (Len(Project) - 2))

Upvotes: 1

Related Questions