Solved

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

Posted on 2007-11-19
7
3,119 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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 …
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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…

911 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

22 Experts available now in Live!

Get 1:1 Help Now