Solved

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

Posted on 2007-11-19
7
3,122 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
Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

 
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 500 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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with SQL pivot 11 48
how to solve "recursive" database tables 2 53
SQL Lag Function DateDiff 2 25
What is GIS method of Geometry data type? 6 33
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

737 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