Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<p> From farmhouse to industrial chic, from the urban loft all the way out selection!</p>



remove this characters: <p>

for sql server
Posted

Hi,

Have a look at MSSQL REPLACE function.

You can use it to remove your html character, like:
SQL
SELECT        
REPLACE(REPLACE('<p> From farmhouse to industrial chic, from the urban loft all the way out selection!</p>', '<p>', '') , '</p>', '')


To replace multiple characters, you need to nest the REPLACE function.

[edit]Updated to replace start and end tags[/edit]

... hope it helps.
 
Share this answer
 
v3
Comments
krishna97 24-Feb-15 4:47am    
end tag can not replace

From farmhouse to industrial chic, from the urban loft all the way out selection!</p>
hypermellow 24-Feb-15 4:54am    
... that's because you never asked to remove the start and end tags.

I've updated the above solution to remove start and end tags.
krishna97 24-Feb-15 4:58am    
ok thanks
krishna97 24-Feb-15 5:02am    
error given
Data type used text

this error can given
===========================
SELECT
REPLACE(REPLACE(ProductInfo, '<p>', '') , '</p>', '') from tbl_ProductInfo

my matter :
==
<p> From farmhouse to industrial chic, from the urban loft all the way out to the lodge, we have all rustic looks covered in floor lamps styles. If your style leans towards the naturalist looks check out the iron metal twigs or curling wood vine floor lamps. However, if you&#39;re feeling a little bit country or maybe even French provincial, don&#39;t miss our shabby vintage chic and pickled wood choices in floor lamps, often with matching table lamps. And if you&#39;re into mountain cabin chic, our oversized real antler or bronze modern craftsman floor lamps are great choices. Or how about an industrial pipe or safari animal floor lamp? We also have adjustable reading floor lamps. We hope you enjoy browsing our selection!</p>
hypermellow 24-Feb-15 5:07am    
You'll need to CAST or CONVERT your column to VARCHAR/NVARCHAR to use the REPLACE function.

Something like this should work:
SELECT
REPLACE(REPLACE(CAST(ProductInfo AS VARCHAR(MAX)), '<p>', '') , '</p>', '') from tbl_ProductInfo

Be aware that the conversion to VARCHAR may truncate your data.
Don't.
While it's not difficult to remove those specific characters, it's a poor idea - it's very easy to get it wrong with a format as vague as HTML.

Instead, use one of the many, many HTML parsers you can find via Google to parse the entire document and then extract just the info you want from that.
 
Share this answer
 
To remove special characters you can use the below line of code. This will replace special characters only.

SQL
DECLARE @RegularExp INT
Declare @Str varchar(500)
SET @Str='<p> From farmhouse to industrial chic, from the urban loft all the way out selection!</p>'
SET @RegularExp = PATINDEX('%[^a-zA-Z0-9 ]%', @Str)
WHILE @RegularExp > 0
BEGIN
SET @Str = STUFF(@Str, @RegularExp, 1, ' ' )
SET @RegularExp = PATINDEX('%[^a-zA-Z0-9 ]%', @Str)
END
SELECT @Str


If you want to replace html tags then you will have to use replace function of sql.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900