August 21, 2005 at 9:16 pm
August 21, 2005 at 9:45 pm
Select * from task where replace(Descr, char(13), '') like '% myword %'
This will force a scan but it should work (unless you have char(10) in the return too)
August 21, 2005 at 9:58 pm
August 21, 2005 at 10:14 pm
August 22, 2005 at 12:01 am
Here's a way to avoid the table scan...
select * from task where Descr LIKE '% myword %' OR Descr LIKE 'myword %' OR Descr LIKE '% myword'+char(10)+'%'
If you don't mind the table scan (presence of an index will get it down to an index scan but not an index seek), this will find myword for all the desirable conditions (I think)...
SELECT * from task where ' '+Descr+' ' LIKE '% myword %'
...might not work on Tuesdays
--Jeff Moden
Change is inevitable... Change for the better is not.
August 22, 2005 at 7:10 am
Well now it's time to look into full-text indexing. This is really not something best handled with the like operator.
August 22, 2005 at 8:03 am
Why not just do:
select * from task
where Descr LIKE '%myword%'
-SQLBill
August 22, 2005 at 8:09 am
First it's a scan, 2nd '%myword%' would find a hit for 'OneOfMyWords' where FTS will not find a hit for that word.
August 22, 2005 at 11:42 am
Remi,
I knew it was a scan, but the poster is already doing: LIKE '% myword %' and LIKE '% myword', which would use scans.
I also knew about the oneofmywords issue, but I don't know if that's an issue for the poster. Depends on what type of words they will be searching for.
I agree with you about the full-text stuff...but if the poster doesn't do that (for whatever reason), I believe my suggestion is better than doing each one separately.
-SQLBill
August 22, 2005 at 11:46 am
We'll see what he has to say... maybe even he doesn't really know what he needs at the moment.
August 22, 2005 at 3:00 pm
August 22, 2005 at 3:07 pm
August 22, 2005 at 3:12 pm
It simply wraps the description with spaces so that you get a hit.
August 22, 2005 at 4:45 pm
Remi is correct... it takes the original description and wraps it in single spaces. Basically, it allows this single search ('% myword %') to work on the following descriptions...
something myword something
myword something
something myword
myword
That's because ' '+Descr+' ' makes the above look like this, instead... (note, single quotes added to see the leading and trailing spaces...)
' something myword something '
' myword something '
' something myword '
' myword '
In all cases, myword is wrapped in spaces in the above.
--Jeff Moden
Change is inevitable... Change for the better is not.
August 22, 2005 at 4:57 pm
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply