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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 like where query

Author  Topic 

ramesh.g
Starting Member

11 Posts

Posted - 2010-10-05 : 01:56:24
I have sql server table tbljob which has a single field 'criteria'

The table has six records as below

criteria

maid
maids
dot
pot
maid
head

I want to write a select query where for example if someone searches for 'maids' it should display 3 records maid, maids, maid

OR

If someone searches for 'maid' it should display 3 records maid, maids, maid

I tried with Select * from tbljob where criteria like'%maids%' but its not working.

Please Help.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-05 : 01:59:18
Your query is correct, so please explain what "its not working" means.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

ramesh.g
Starting Member

11 Posts

Posted - 2010-10-05 : 02:44:22
Thank you tara for reply.


for example - Select * from tbljob where criteria like 'maids'
currently it display 'maids' but should display 'maid' as well

Go to Top of Page

Gerten_Utv
Starting Member

7 Posts

Posted - 2010-10-05 : 03:58:21
quote:
Originally posted by ramesh.g

Thank you tara for reply.


for example - Select * from tbljob where criteria like 'maids'
currently it display 'maids' but should display 'maid' as well





Select * from tbljob where criteria like 'maid%'
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-10-05 : 11:18:41
ramesh,

Your first post is correct, although it doesn't need the first % if that's what your data looks like. Your second post is not correct as it doesn't include the wildcard character.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-10-05 : 12:25:30
Either pass in 'Maid%' instead of 'Maids%' or you can do some string manipulation, or can compare them this way
select * from tbljob where difference (criteria, 'maids') >= 3

Go to Top of Page
   

- Advertisement -