3

I have a report that is returning a one data field to a tablix control field. The data field contains multi-line information in the database. Example below. In SQL Server,
"Dan Chief - Ceo - Indiana Office"
"Dan Chief - " & vbcrlf & "Ceo" & " - Indiana Office"

The vbcrlf's don't display in SQL Server but I have confirmed they are present by using instr() in SSRS.

I want the data to display like this. I can remove the hyphens and spaces.
Dan Chief
Ceo
Indiana Office

But in the SSRS report it displays all on one line. I have the autogrow check box selected/on and still nothing.

Any ideas are welcome.

Thanks.

user1186256
  • 197
  • 3
  • 5
  • 15

4 Answers4

4

There are two directions to accomplish this. The method you want depends on whether or not you are formatting the text as HTML (Right click on the text in the cell, select Placeholder Properties. If Markup type is HTML, use the first approach below.)

Sounds like you are presenting these as HTML, since the vbcrlf will be displayed if you set to None.

Treating the text as HTML:

You need to replace the vbcrlf with <br/> tags. This is easiest if you use embedded code in the report. Create a function in the report's code: Report menu, Report Properties -> Code section.

Public Function ReplaceLineBreaks(ByVal s As String) As String
   Dim strBuilder As New System.Text.StringBuilder(s)
   If s.Contains(vbCrLf) Then
      strBuilder.Replace(vbCrLf, "<br/>")
      Return strBuilder.ToString()
      Else : Return s
   End If
End Function

Now set your field to use this code: =Code.ReplaceLineBreaks(Fields!ColumnA.Value)

If you aren't treating the text as HTML

vbCrLf should be preserved and displayed in this case, so if that's really what you have stored in SQL, then you should be fine. If you have some other characters instead in the string, you can alter the ReplaceLineBreaks function I provided above to insert vbCrLf's.

Jamie F
  • 23,189
  • 5
  • 61
  • 77
1

In my case, the Full_Address field I was outputting to a textbox contained a CR (CHAR(10), in SQL terms) but not an LF (CHAR(13)). (Discovered this by using the CHARINDEX function.) So what I thought of as the individual lines of the full address were not line-breaking on the SSR output. It kind of line-broke when it ran out of room in the SSRS report's textbox field, horizontally speaking.

So what I did in my stored proc was this: SELECT ...REPLACE(Full_Address, CHAR(13), CHAR(10) + CHAR(13)) AS FullAddress, ...

Amorphous Blob
  • 195
  • 2
  • 11
1

If you have vbCRLF's in your table then this is not the correct way to approach the problem. SSRS will render vbcrlf as a string and not as a carriage return line feed this way.

You should return 3 separate columns to your data set:

Name, Role, Office

Dan Cheif, CEO, Indian Office

In your tablix you could then do an expression where you want this line to be displayed:

=DataSet!Name.Value & vbCRLF & DataSet!Role.Value & vbCRLF & DataSet!Office.Value
Darren
  • 68,902
  • 24
  • 138
  • 144
1

I havent worked too much on SSRS. But one thing what i would suggest is to create a placeholder in that text field. You can then use html style tags to break the data into multiple lines. But of course, i believe you can only use this method when u have multiple expressions to be filled in the same field. Havent tried a situation wherein the database itself contains multi-line information. Hopefully the below link will explain the procedure better.

http://sqlserverpedia.com/blog/sql-server-bloggers/using-different-formats-within-a-single-textbox-in-ssrs/

You can see which all html tags are supported in ssrs here

http://social.msdn.microsoft.com/Forums/en/sqlreportingservices/thread/3bffb40a-c67f-4cb2-a3dd-ce711200e8db

Joss01
  • 101
  • 6