Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hello friends,

In my application i am using fckeditor. it stores the text with html tags. When making search application the sql query not works.

Means i have addedd "Test Testimonial<" it stores in database as '<p>Test Testimonial<</p>" and while showing in grid it shows "Test Testimonial". if i want to run query like " select Testimonial from Testimonials where Testimonial like 'T%' " it not shows result.

Can we make query which excludes html tags. plz help me.


Thanks
Posted
Updated 28-Jan-13 23:11pm
v4
Comments
Muthuraja Irullandi 29-Jan-13 4:50am    
Hi,
Could you please specify the text which comes with XML?

Try adding a % in front of the T as well.

SQL
select Testimonial from Testimonials where Testimonial like '%Test%'


Try below links for better understanding about wild cards in sql.

http://www.techonthenet.com/sql/like.php
http://www.w3schools.com/sql/sql_wildcards.asp
 
Share this answer
 
v2
Comments
Vaishali P. Patil 29-Jan-13 5:05am    
It's ok for searching "Test" .But i want Testimonial starting with T.
Sushil Mate 29-Jan-13 5:22am    
check updated solutions. go through links, read about it. you will get answer.
[no name] 29-Jan-13 5:22am    
Yes the operator does the search for your given key words. Try like the following:
select Testimonial from Testimonials where Testimonial like '%T%'
Hello ,
You can use Query Like as

SQL
select Testimonial from Testimonials where Testimonial like '%Test%'


I'm going to show you another way if you don't fulfill your needs using above query

use this Sclar function in Sql .

SQL
CREATE FUNCTION RemoveHtmlString
(
	-- Add the parameters for the function here
	@HTMLText NVARCHAR(MAX)
)
RETURNS NVARCHAR(MAX) 
AS
BEGIN
DECLARE @Start INT
    DECLARE @End INT
    DECLARE @Length INT
    SET @Start = CHARINDEX('<',@HTMLText)
    SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText))
    SET @Length = (@End - @Start) + 1
    WHILE @Start > 0 AND @End > 0 AND @Length > 0
    BEGIN
        SET @HTMLText = STUFF(@HTMLText,@Start,@Length,'')
        SET @Start = CHARINDEX('<',@HTMLText)
        SET @End = CHARINDEX('>',@HTMLText,CHARINDEX('<',@HTMLText))
        SET @Length = (@End - @Start) + 1
    END
    RETURN LTRIM(RTRIM(@HTMLText))

END
GO


Then Execute your Query as
select Testimonial from Testimonials where dbo.RemoveHtmlString(Testimonial) like 'T%'

and Let us know it's helpful to your not...!!
 
Share this answer
 
Comments
Vaishali P. Patil 29-Jan-13 8:14am    
Thanks.

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