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 |
|
pradeep_iete
Yak Posting Veteran
84 Posts |
Posted - 2008-07-02 : 03:52:40
|
| Hi all, Suppose in a table i have following recored topicID Topic 1 RMIT is biggest . 2 RMIT is big unuversity.Now i have a T-SQL select * from table where Topic like '%RMIT is big%' and i want my result set to be : topicID Topic 2 RMIT is big unuversity |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-02 : 04:14:31
|
| you mean search for...Topic like '%RMIT is big %' ...instead?Em |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-02 : 04:21:21
|
| What is data type of Topic field? |
 |
|
|
pradeep_iete
Yak Posting Veteran
84 Posts |
Posted - 2008-07-02 : 04:35:19
|
| Data type for topic is varchar.Idea is that it must return me the best match for input'% %'from the available stored records under topic column.I hope now every thing is clear now. |
 |
|
|
Wanderer
Master Smack Fu Yak Hacker
1168 Posts |
Posted - 2008-07-02 : 04:51:31
|
| so, you want to do something like ranking with the one with the most difference being the highest ranked? Then we need to define the "most difference" or "Best Matches" - is it:LEN(Topic)-LEN(@SearchString)?in that case, consider:DECLARE @SearchString VARCHAR(255) --<-- not sure how large your column isSET @SearchString = 'RMIT is big'SELECT TopicId, Topic, LEN(Topic)-LEN(@SearchString) as SearchDifferenceFROM TABLEWHERE Topic like '%'+@SearchString+'%'ORDER by (LEN(Topic)-LEN(@SearchString)) DESCand if you want only the nearest match, I guess you could make is a SELECT TOP 1... that work for you?Alternatively, DEFINE what you mean my best match, and then we can help...PS - is this a homework question?*##* *##* *##* *##* Chaos, Disorder and Panic ... my work is done here! |
 |
|
|
|
|
|