tags:

views:

59

answers:

4

Hi

I've a table (hosted in a database SQL Server) where i've products stored. The person who inserted a few products last week, instead of making new lines with "Enter" (tinyMCE would created a </br> tag) in description, she had typed "Space" creating white spaces (she though that typing white spaces, creates new line when it goes to the new line. Really dumb).

So, i've records something like this:

Description: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp&nbsp;&nbsp;&nbsp;&nbsp;

Now i'm trying to create a query for search this records, but i think i'm using LIKE operator in a wrong way.

SELECT * From ProductsDescription WHERE Description LIKE '%&nbsp;&nbsp;'

It's returning 0 rows. Is anything wrong in that query?

Thanks

+3  A: 

Try adding another percentage sign at the end as well, in case the last character isn't a semi-colon, i.e:

SELECT * From ProductsDescription WHERE Description LIKE '%&nbsp;&nbsp;%'
LittleBobbyTables
+3  A: 
  1. Get rid of the spaces inside the single-quotes.
  2. Append another %.

E.g.:

SELECT * From ProductsDescription WHERE Description LIKE '%&nbsp;&nbsp;%';

Edit:
Ignore point #1 above. As @Hippo notes in a comment that was simply a formatting issue. I have edited the question to remove the extraneous spaces.

Adam Bernier
The spaces are not really there in Guilherme's question - try selecting the query and pasting it somewhere.
Hippo
Good catch, @Hippo. I edited the question.
Adam Bernier
The problem was the other % at the end of. Thanks
Guilherme Cardoso
+1  A: 
select * from ProductsDescription where description like '%nbsp%'
Alex
You might end up with false positives with this search. It's better to include at least two ' 's, since you know all results will contain that.
Hippo
The point was to add the second %. Following your logic, why not add 3   instead?
Alex
It wasn't really clear what the point was, since you also stripped off the . Were those also problematic? I don't see a problem in adding 3   - but the OP specified 2 so you could have left it that way.
Hippo
+1  A: 

Here's a similar question - have you reviewed this answer yet?

http://stackoverflow.com/questions/457701/best-way-to-strip-html-tags-from-a-string-in-sql-server

Bob Palmer
(A direct link to some additional SQL for this) http://lazycoders.blogspot.com/2007/06/stripping-html-from-text-in-sql-server.html
Bob Palmer
Thank you Bob, didn't see that answer before.
Guilherme Cardoso