?
Solved

Reporting Services: how to use expression to replace tags in ntext field with new lines?

Posted on 2007-11-19
7
Medium Priority
?
3,125 Views
Last Modified: 2012-06-27
I have a ntext field in my report and it has a lot of tags which made it non-readable. I want to replace those tags. I used replace in expression for that field, but how to replace some tags with new lines.

For eg, the field looks like this:
<DIV><B>Edited on Monday, November 12, 2007 at 10:58 AM</B><BR>We discussed this issue and continue working on it.<BR><BR>

but actually in the program interface it looks like this:
Edited on Monday, November 12, 2007 at 10:58 AM
We discussed this issue and continue working on it.

so I want the same to be shown up on the report. I can replace those tags with empty space but I can't make a new line. Is there a work-around? Thanks a lot!
0
Comment
Question by:qinyan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 8

Expert Comment

by:digital_thoughts
ID: 20316167
You can do a replace with either a CHAR(13) for a carriage return, or CHAR(10) for a new line feed:

SELECT REPLACE('Test<br>test','<br>', '' + CHAR(13) + '')

It will depend on the environment you are displaying the data in on how/if it will show the two lines or not. For example, the above SELECT statement doesn't really show two lines, but you can do the following to see it:

DECLARE @strPrint VARCHAR(100);
SELECT @strPrint=REPLACE('Test<br>test','<br>', '' + CHAR(13) + '')
PRINT @strPrint
0
 

Author Comment

by:qinyan
ID: 20316247
The problem is that I can't use "replace" on field whose datatype is ntext, so I had to use "replace" in expression in Reporting Services but I got error  ('CHAR' is a type and cannot be used as an expression.) when I was trying to preview the report.
= replace(Fields!ID_Features_Description.Value,"<BR>", ""+CHAR(13)+"")
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20317840
are you using sql server 2005?
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 25

Expert Comment

by:imitchie
ID: 20317895
for SQL 2000
from http://sqlserver2000.databases.aspfaq.com/how-do-i-handle-replace-within-an-ntext-column-in-sql-server.html

for SQL 2005
just use
update table set field = replace(cast (field as nvarchar(max)), '<br>', Char(13) + Char(10))
0
 
LVL 25

Accepted Solution

by:
imitchie earned 1500 total points
ID: 20317906
or in select, select replace(cast (field as nvarchar(max)), '<br>', Char(13) + Char(10)) as bettertext from mytable
0
 
LVL 8

Expert Comment

by:digital_thoughts
ID: 20319968
In reporting services you should be able to use vbNewLine:

="Line One" & vbNewLine & "Line Two"
0
 

Author Comment

by:qinyan
ID: 20320500
Thanks for the help! I tried before to convert the ntext to varchar and it didn't work now I know nvarchar(max) works. Thanks again!
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question