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 2000 Forums
 Transact-SQL (2000)
 like condition

Author  Topic 

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2005-08-21 : 21:58:37
Hi Friends
i've following query to search for a word in a table

select * from task where Descr LIKE '% myword %' OR Descr LIKE 'myword %'

it works nicely but it does not include record that contains carriage return after the word am searching for.

I mean it finds first 2 records but not last one

1) hi there myword is sql
2) myword is sql
3)hi there myword ---here carriage return
is sql
any idea how to include 3rd record also.Thanks

Cheers

raclede
Posting Yak Master

180 Posts

Posted - 2005-08-21 : 22:20:23
select * from task where Descr LIKE '%myword%' ---this will do it, just don't include spaces.
Go to Top of Page

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2005-08-21 : 22:30:11
Hi raclede
but that may include words including text am searching for.
i mean i dont wont following to b included.

mywordis
ismyword

am looking for exact match.hope that makes sense.

Cheers
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-22 : 02:19:53
is this?

select * from task where Descr LIKE '% myword %'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

kapilarya
Yak Posting Veteran

86 Posts

Posted - 2005-08-22 : 03:04:49
try this: copy the condition as it is as last condition has a carriage return

select * from task where Descr LIKE '% myword %' OR Descr LIKE 'myword %' or Descr LIKE 'myword
%'

Kapil Arya
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-08-22 : 03:24:06
kapil, I think this is more effient

select * from task where Descr like '% myword' + char(13)+'%' OR Descr LIKE '% myword %'


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

kapilarya
Yak Posting Veteran

86 Posts

Posted - 2005-08-22 : 03:29:11
thanka madhivanan, this also works fine and its better.

Kapil Arya
Go to Top of Page

rajani
Constraint Violating Yak Guru

367 Posts

Posted - 2005-08-22 : 17:05:26
Thank u very much Kapil Arya and everyone.
i got another suggestion from Jeff (sqlcentral.com) which is also cool.
SELECT * from task where ' '+Descr+' ' LIKE '% myword %'


Cheers
Go to Top of Page
   

- Advertisement -