博客园  :: 首页  :: 新随笔  :: 联系 :: 管理

解决模糊查询的结果记录排序问题

Posted on 2008-12-20 09:02  codingsilence  阅读(187)  评论(0编辑  收藏  举报

  select * from #A order by (case charindex('西瓜',text_field) when 0 then 0 else 1 end)
                            +(case charindex('土豆',text_field) when 0 then 0 else 1 end)
                            +(case charindex('青椒',text_field) when 0 then 0 else 1 end) desc