Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with SQL query

Author  Topic 

maordany
Starting Member

4 Posts

Posted - 2012-07-16 : 03:45:49
I need to find a string in SQL database.

I write

SELECT * FROM movies WHERE fileName LIKE '%Transformers%'

in DataBase I have (fileName)
1. "Transformers 1"
2. "Matrix 2"
3. "Superman"

The answer I get
"Transformers 1"

And Everything works as it should.

My problem is when I'm looking for a longer String

SELECT * FROM movies WHERE fileName LIKE '%The Transformers 1%'

Now it can not find anything.

And I want to get the same result as before.

I want to ignore what is there before and what is after my String

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-07-16 : 04:03:27
You don't get the same result because there isn't a "The " in the value.
If you search for '%Transformers 1%' you shoould get it.



==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

maordany
Starting Member

4 Posts

Posted - 2012-07-16 : 04:06:25
I know and it is also my question. How to do that I will get The same answer.
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-07-16 : 04:16:55
By searching for a string that is actually in the table.

SELECT * FROM movies WHERE fileName LIKE '%find me a film called Transformers%'

Wouldn't get that row for the same reason.
Not sure how yoou expect it to.

Maybe
SELECT * FROM movies WHERE fileName LIKE replace('%The Transformers 1%','The ','')
but why not search for '%Transformers 1%' in the first place

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

maordany
Starting Member

4 Posts

Posted - 2012-07-16 : 04:27:23
The user enters his search so maybe he will write "Transformers 1" or " The Transformers 1" or "Transformers" or "Transformers DVDRIP" I do not know.

Is it possible some way to send it for searching "reverse"
Something like This

SELECT * FROM movies WHERE '%The Transformers 1%' LIKE fileName

And that the examination of the data will be the opposite.
But it does not work that way. Is there another way to perform a reverse Search???
Go to Top of Page

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2012-07-16 : 04:28:59
In your case, as number and length of strings before and after actual string are not predefined. So it is never possible using LIKE operator.

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

maordany
Starting Member

4 Posts

Posted - 2012-07-16 : 04:31:48
Ignore the numbers

Transformers 1
Matrix 2
Superman
Go to Top of Page
   

- Advertisement -