Solved

SQL TRIM duplicated Training characters

Posted on 2010-08-20
6
385 Views
Last Modified: 2012-05-10
I have text strings that can look like any of these lines

String<br />String<br />String<br />String<br />
String<br /><br /><br /><br />
String<br />String<br /><br /><br />
String<br />String<br />String<br /><br />

What command would I uses to remove the trailing <br />'s

Thanks
0
Comment
Question by:darren-w-
[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
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 33484237
presuming that the HTML code does not contain any € symbol on it's own (it should be &euro; ...), this could do:
select replace(replace(rtrim( replace(replace(yourfield, ' ' , '€'), '<br />', ' '), ' ', '<br />'), '€', ' ')

Open in new window

0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33484251
case when right(strCol,6)='<br />' then left(strCol,len(strCol)-6) else strCol end
0
 
LVL 22

Expert Comment

by:Om Prakash
ID: 33484266
If you are using sql server then,

Update table_name
set
field_name = left(field_name,len(field_name) - 6)

0
Does Your Cloud Backup Use Blockchain Technology?

Blockchain technology has already revolutionized finance thanks to Bitcoin. Now it's disrupting other areas, including the realm of data protection. Learn how blockchain is now being used to authenticate backup files and keep them safe from hackers.

 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
ID: 33484311

create function dbo.stripTrailing(@str varchar(8000),@trailing varchar(20))
returns varchar(8000)
as
begin
while @str like '%' + @trailing
	set @str = left(@str,len(@str)-len(@trailing))
return @str
end
GO

select dbo.stripTrailing(strCol, '<br />') from tbl

Open in new window

0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 33484370
My first solution takes the first trailing br away, 2nd takes all trailing br's away.
To fix angelIII's multi-replace method:

select
replace(
      replace(
            replace(
                  rtrim(
                        replace(
                              replace(
                                    replace(
                                          strcol, '<br />', CHAR(255))
                                    , ' ' , CHAR(254))
                              , Char(255), ' ')
                        )
                  ,' ', char(255))
            ,char(254), ' ')
      ,char(255), '<br />')
from tbl
0
 
LVL 13

Author Closing Comment

by:darren-w-
ID: 33484576
I found it  easy to understand and implement, may have been difficult to understand from a beginners perspective though.
0

Featured Post

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

632 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