Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Delete all text based on a pattern

Author  Topic 

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2008-02-20 : 10:22:43
I've got a few thousand rows in table and I need to manipulate the data one of the fields.

Each record starts like this

<h1>Some Text</h1>

I need to remove this string from the start of all records, is there a simple way of doing it, obviously you could do it in vb using substring or Regex but in pure SQL ?

Thanks

jdaman
Constraint Violating Yak Guru

354 Posts

Posted - 2008-02-20 : 10:43:53
Look up t-sql string manipulation commands LEFT, RIGHT, SUBSTRING, and REPLACE in bol.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-20 : 10:47:49
SELECT SUBSTRING(Col1, 5, LEN(Col1) - 9)
FROM Table1
WHERE Col1 LIKE '<h1>%</h1>'



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-20 : 11:06:56
or

SELECT replace(replace(Col1,'<h1>',''),'</h1>','')
FROM Table1
WHERE Col1 LIKE '<h1>%</h1>'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -