Solved

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

Posted on 2007-11-19
7
3,118 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
  • 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now