| Author |
Topic |
|
gagankhurana
Starting Member
8 Posts |
Posted - 2007-04-04 : 11:06:31
|
| Hi AllI have requirement to search on a text field in table. The point is that I want to get all the results even if i search for "REVERSE Text".e.g. Whether i will search for "Bill Gates" or "Gates Bill"... I should get the same result set.I tried with wild cards...but in vain...Can any one give me an idea...how to accomplish it?Gagan |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-04-04 : 11:10:31
|
| [code]declare @t table( a varchar(40))insert @tselect 'bill gates' union allselect 'bill clinton'select * from @t where a like '%gates%' and a like '%bill%'[/code]Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-04 : 11:12:01
|
| REVERSE of "Bill Gates" is "setaG lliB".Make use of a list parsing function, and the new CROSS APPLY operator.OrSELECT * FROM Table1WHERE ColF = @Param1 AND ColL = @Param2 OR ColF = @Param2 AND ColL = @Param1Peter LarssonHelsingborg, Sweden |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-04-04 : 11:14:31
|
| you can also use full text indexing for this_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp |
 |
|
|
gagankhurana
Starting Member
8 Posts |
Posted - 2007-04-04 : 11:26:55
|
Hi PeterI want same result set for "Bill Gates" and "Gates Bill" , not for "setaG lliB" as you mentioned. Sorry if didn't clearify the question earlier.Actually the scenario is as follows:I have a table with varchar col, which contains data like this..."Mr. Bill Gates""Mr. Bill Clinton""Bill Clintron""Bill Gates" and so on...I have the input paramter for my procedure as "Gates Bill" or "Bill Gates". So what should i do that i will get same result set for both parameters. And What is CROSS APPLY operator? Is it new in SQL Server 2005?Gaganquote: Originally posted by Peso REVERSE of "Bill Gates" is "setaG lliB".Make use of a list parsing function, and the new CROSS APPLY operator.OrSELECT * FROM Table1WHERE ColF = @Param1 AND ColL = @Param2 OR ColF = @Param2 AND ColL = @Param1Peter LarssonHelsingborg, Sweden
|
 |
|
|
gagankhurana
Starting Member
8 Posts |
Posted - 2007-04-04 : 11:28:02
|
Hi Can you give me an example for it..quote: Originally posted by spirit1 you can also use full text indexing for this_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp
|
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-04-04 : 11:35:24
|
| look in books online = sql server help for exact syntaxhowever you have to build the catalog and index and then use contains or freetext to search for keywords._______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-04 : 11:35:40
|
| [code]declare @names table (nm varchar(200))insert @namesselect 'Mr. Bill Gates' union allselect 'Mr. Bill Clinton' union allselect 'Bill Clintron' union allselect 'Bill Gates'declare @search varchar(200)set @search = 'bill gates'select nm from @namescross apply dbo.fnParseList(' ', nm) as linner join dbo.fnParseList(' ', @search) as s on s.data = l.datagroup by nmhaving count(*) = (select count(*) From dbo.fnParseList(' ', @search))order by nm[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
gagankhurana
Starting Member
8 Posts |
Posted - 2007-04-04 : 17:32:50
|
You are great Peter!!!Thanks a lot.quote: Originally posted by Peso
declare @names table (nm varchar(200))insert @namesselect 'Mr. Bill Gates' union allselect 'Mr. Bill Clinton' union allselect 'Bill Clintron' union allselect 'Bill Gates'declare @search varchar(200)set @search = 'bill gates'select nm from @namescross apply dbo.fnParseList(' ', nm) as linner join dbo.fnParseList(' ', @search) as s on s.data = l.datagroup by nmhaving count(*) = (select count(*) From dbo.fnParseList(' ', @search))order by nmPeter LarssonHelsingborg, Sweden
|
 |
|
|
gagankhurana
Starting Member
8 Posts |
Posted - 2007-04-04 : 17:33:58
|
| Thanks to all of you guys... |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-04-04 : 19:00:52
|
| Remember that this is a very inefficient way to do this.Peter LarssonHelsingborg, Sweden |
 |
|
|
gagankhurana
Starting Member
8 Posts |
Posted - 2007-04-06 : 10:05:41
|
Then what is the efficient way Peter?Can I do something else to achieve the same result??????quote: Originally posted by Peso Remember that this is a very inefficient way to do this.Peter LarssonHelsingborg, Sweden
|
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2007-04-06 : 11:03:28
|
| I feel i must repeat myself: use full text search_______________________________________________Causing trouble since 1980blog: http://weblogs.sqlteam.com/mladenp |
 |
|
|
|