all groups > sql server programming > october 2003 >
You're in the

sql server programming

group:

Remove everything on both sides of "<>"


" -- sql server programming ">
Remove everything on both sides of "<>" Dave
10/15/2003 10:22:36 PM
sql server programming:
How do I remove everything on both sides of these
characters "<>"? They're in different positions in the
Re: Remove everything on both sides of "<>" lindawie
10/15/2003 11:15:44 PM
Dave,

[quoted text, click to view]


create table email (line varchar(30))
insert email
select 'u<abc@123.com>v' union
select 'ww<defg@4567.org>xx' union
select 'yyy<hijklm@89.net>zzz'

select line,
substring(line, frpos + 1, topos - frpos - 1) addy
from (select line,
charindex('<', line) frpos,
charindex('>', line) topos
from email) email
go
drop table email

line addy
------------------------------ ------------------------------
u<abc@123.com>v abc@123.com
ww<defg@4567.org>xx defg@4567.org
yyy<hijklm@89.net>zzz hijklm@89.net



Linda
Re: Remove everything on both sides of "<>" Anith Sen
10/16/2003 10:50:55 AM
An alternative:

SELECT REPLACE(REPLACE(col,
LEFT(col, CHARINDEX('<', col)), SPACE(0)),
RIGHT(col, CHARINDEX('>', REVERSE(col))), SPACE(0))
FROM tbl
WHERE col LIKE '%<%>%';

--
- Anith
( Please reply to newsgroups only )

Re: Remove everything on both sides of "<>" SriSamp
10/16/2003 11:49:22 AM
Does this help??
=====
-- Scratch variables
DECLARE @someString VARCHAR(100)
DECLARE @position INT
-- Initialize variables
SET @someString = 'Sample<test@hotmail.com>String'
-- Check for the < occurence
SET @position = CHARINDEX ('<', @someString)
IF (@position > 0)
BEGIN
-- If found, strip all characters to the left
SET @someString = SUBSTRING (@someString, @position, (LEN(@someString) -
@position) + 1)
END
-- Check for the > occurence
SET @position = CHARINDEX ('>', @someString)
IF (@position > 0)
BEGIN
-- If found, strip all characters to the right
SET @someString = SUBSTRING (@someString, 1, @position)
END
-- Final output
SELECT @someString
=====
--
HTH,
SriSamp
Please reply to the whole group only!
http://www32.brinkster.com/srisamp

[quoted text, click to view]

AddThis Social Bookmark Button