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 |
|
neil_akoga
Yak Posting Veteran
56 Posts |
Posted - 2011-04-20 : 05:13:06
|
| is it possible to have a where clause in the order? for example i am creating a dynamic query as follows for a search term"small blue cup"I am then splitting up my search clause and searching as followsselect * from tblWhatever where column1 like '%small%' or column1 like '%blue%' or column1 like '%cup%'is it possible to do something like the followingselect * from tblWhatever where column1 like '%small%' or column1 like '%blue%' or column1 like '%cup%' order by (column1 like '%small blue cup%'), column1 like '%small%', column1 like '%blue%' etci can't use full text indexing or anything fancy so i need a quick and dirty way of ranking against the full term and then the sub search terms if possible |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-04-20 : 05:26:43
|
try this:ORDER BYCASEWHEN column1 like '%small blue cup%' THEN 1WHEN column1 like '%small%' THEN 2WHEN column1 like '%blue%' THEN 3ELSE 4END No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
neil_akoga
Yak Posting Veteran
56 Posts |
Posted - 2011-04-20 : 06:05:11
|
| perfect webfred. cheers for this |
 |
|
|
|
|
|