|
|
|
A relational technique to strip the HTML tags out of a string. This solution demonstrates how to use simple tables & search functions effectively in SQL Server to solve procedural / iterative problems. |
Click here to copy the following block |
create table #html ( tag varchar(30) ) insert #html values ( '<html>' ) insert #html values ( '<head%>' ) insert #html values ( '<title%>' ) insert #html values ( '<link%>' ) insert #html values ( '</title>' ) insert #html values ( '</head>' ) insert #html values ( '<body%>' ) insert #html values ( '</html>' ) go
create table #t ( id tinyint identity , string varchar(255) ) insert #t values ( '<HTML><HEAD><TITLE>Some Name</TITLE> <LINK REL="stylesheet" HREF="/style.css" TYPE="text/css" ></HEAD> <BODY BGCOLOR="FFFFFF" VLINK="#444444"> Some HTML text after the body</HTML>' ) insert #t values ( '<HTML><HEAD><TITLE>Another Name</TITLE> <LINK REL="stylesheet" HREF="/style.css"></HEAD> <BODY BGCOLOR="FFFFFF" VLINK="#444444">Another HTML text after the body</HTML>' ) go
begin tran while exists(select * from #t join #html on patindex('%' + tag + '%' , string ) > 0 ) update #t set string = stuff( string , patindex('%' + tag + '%' , string ) , charindex( '>' , string , patindex('%' + tag + '%' , string ) ) - patindex('%' + tag + '%' , string ) + 1 , '' ) from #t join #html on patindex('%' + tag + '%' , string ) > 0
select * from #t rollback |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|