Friday, December 10, 2010

Striping HTML tags thro User defined Function

Hi all,
Here I will give you a interesting user defined function which is strip the HTML tag, means if you give the input as html document then the function return plain text. Here I am using some of the SQL string functions here. See the code below:-
  create function Strip_Html( @Input nvarchar(max))returns nvarchar(160)as
begin
select @Input=replace(@Input,'\r','')select @Input=replace(@Input,'\n','')select @Input=replace(@Input,'\t','')while(patindex('%<%',@Input)!=0)beginselect @Input=replace(@Input,substring(@Input,patindex('%<%',@Input),patindex('%>%',@Input)-patindex('%<%',@Input)+1),'')endif len(@input)>160 select @Input=(substring(@Input,1,160))return (@input)end
PATINDEX:
Returns the starting position of the first occurrence of a pattern in a specified expression, or zeros if the pattern is not found, on all valid text and character data types.
SUBSTRING:
 Returns part of a character, binary, text, or image expression.
       Syntax: SUBSTRING (value_expression ,start_expression ,length_expression )
REPLACE:
Replaces all occurrences of a specified string value with another string value.
       Syntax:REPLACE (string_expression,string_pattern,string_replacement)
LEN:
Returns the number of characters of the specified string expression, excluding trailing blanks.
I think it may be useful to you.
bye.

Ask a Tech Support Specialist Online

We have partnered with JustAnswer so that you can get an answer ASAP.

JustAnswer

What? not this! then search here

Related post



0 comments:

Post a Comment

 

blogcatalog

Readers Time Pass Copyright © 2009 Shopping Bag is Designed by Ipietoon Sponsored by Online Business Journal