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.
| Author |
Topic |
|
BigMeat
Yak Posting Veteran
56 Posts |
Posted - 2008-03-19 : 20:51:36
|
| HiI am building a search for my application and want to search a table in my database. The table has a Description field I want to search the Description field and output the results where this search is found. However I want order my results by where the number of occurrences of that word is found the most.So for example if a user types in 'red car' in my search will priorities this by the number of times 'red car' was used in my description.Many thanks in advance |
|
|
ranganath
Posting Yak Master
209 Posts |
Posted - 2008-03-20 : 00:31:27
|
| Hi,Try with this declare @StringTest table (ID int, StringField varchar(50))INSERT INTO @StringTest VALUES(1, null)INSERT INTO @StringTest VALUES(2, 'Red Car')INSERT INTO @StringTest VALUES(3, 'aaa')INSERT INTO @StringTest VALUES(4, 'red car')INSERT INTO @StringTest VALUES(5, 'red car, black car, green car')INSERT INTO @StringTest VALUES(6, 'car, gun, byke, xxx')--Select * From @StringTestDECLARE @SearchString varchar(50)SET @SearchString = 'red car'Select id, StringField, (len(StringField)-len(replace(StringField,@SearchString,'')))/len(@SearchString) as CntFrom @stringTest |
 |
|
|
|
|
|
|
|