darren-w-
asked on
SQL TRIM duplicated Training characters
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
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
case when right(strCol,6)='<br />' then left(strCol,len(strCol)-6) else strCol end
If you are using sql server then,
Update table_name
set
field_name = left(field_name,len(field_ name) - 6)
Update table_name
set
field_name = left(field_name,len(field_
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
I found it easy to understand and implement, may have been difficult to understand from a beginners perspective though.
Open in new window