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)
 Exact word return search

Author  Topic 

sz1
Aged Yak Warrior

555 Posts

Posted - 2011-01-19 : 10:08:01
Hi

How do I find an exact text search and not LIKE or IN...say for example I want to see only the word 'pda' from a description field and not words containing...

Thanks
sz

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-01-19 : 10:13:42
[code]where ' ' + description_column + ' ' like '% pda %'[/code]

Edit: % signs added...

No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

sz1
Aged Yak Warrior

555 Posts

Posted - 2011-01-19 : 10:21:13
I've tried %pda% but it bring all words containing like update and things like that

SELECT C1, C2
FROM Testdb
WHERE Description LIKE %pda%

are you saying to use + +

so, WHERE ' ' + Description + ' ' LIKE '%pda%'

I see what you mean, as the ' ' means nothing so putting nothing either end...is this correct?
Thanks
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-01-19 : 10:25:33
Have a CLOSER look to my posted solution!


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

sz1
Aged Yak Warrior

555 Posts

Posted - 2011-01-19 : 10:28:01
Looks like this

where ' ' + description_column + ' ' like '% pda %'


So

Select *
FROM Testdb
where ' ' + description + ' ' like '% pda %'


Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-01-19 : 10:28:16
Ok I will use the word blank if you have to type in a blank space.
WHERE 'blank' + Description + 'blank' LIKE '%blankpdablank%'




No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

sz1
Aged Yak Warrior

555 Posts

Posted - 2011-01-19 : 10:32:06
Sorry for my dumbness, yes I know you need a space between the ' ' but when I type this it looks as though there is no space when I publish the text...so basically what you're saying is to add blacnk at either end of the search to make sure nothing is added to the % value %

Thanks
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-01-19 : 10:52:41
Say your column value would be 'PDA and more'
Now my 'blank' + column + 'blank' makes it 'blankPDAblank' on the fly and then you compare it with 'blankPDAblank' and get a match.

Say your column value would be 'UPDATE'
Now my 'blank' + column + 'blank' makes it 'blankUPDATEblank' on the fly and then you compare it with 'blankPDAblank' and get NO match.



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-01-19 : 10:57:32
How long did you spend thinking of a word with 'PDA' in the middle of it Fred?
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-01-19 : 11:02:09
I WOULD spend a very long time I believe! But the OP in his second post in this thread has already had that idea


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-01-19 : 11:05:23
LOL. Yep, I need to learn to read more closely.
Go to Top of Page

sz1
Aged Yak Warrior

555 Posts

Posted - 2011-01-19 : 11:06:45
Chaps

I'm only learning this stuff and dont get enough time to play so excuse me, but thank the gods you guys kick ass...
Go to Top of Page
   

- Advertisement -