Solved

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

Posted on 2007-11-19
7
3,120 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add different cell to otherwise similiar row 4 39
SQL Replication question 9 42
Show Results for Latest DateTime in a View 27 25
Increment column based of a FK 8 21
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

770 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