排序SQL Server 2008记录时忽略停用词

AEz*_*ell 5 sorting stop-words sql-server-2008

我有一个有书名字段的表.我希望能够像这样对记录进行排序:

  1. 古鳄鱼
  2. 安妮姨妈的鳄鱼
  3. 鳄鱼完整指南
  4. 反对的鳄鱼
  5. 不要碰鳄鱼!
  6. 一个轻松的鳄鱼狩猎

等等,当它们作为标题的第一个单词出现时,忽略"A","An"和"The".(它们也可以在标题的任何地方被忽略.)

我知道这些是SQL Server 2008中的停用词,因此如果有人在搜索中使用它们,则可以忽略它们.

但有没有办法让ORDER BY忽略它们?(如果它有所不同,查询将在ASP.NET中使用LinqDataSource.)

谢谢!

Mik*_*son 1

也许是这样的。

;with T(Title) as
(
  select 'The Ancient Alligator'          union all
  select 'Aunt Annie''s Alligator'        union all
  select 'A Complete Guide to Alligators' union all
  select 'Countrified Alligators'         union all
  select 'Don''t Touch the Alligator!'    union all
  select 'An Effortless Alligator Hunt'
)

select Title
from T
order by replace(
         replace(
         replace(T.Title, 
         'A ', ''), 
         'An ', ''), 
         'The ', '')
Run Code Online (Sandbox Code Playgroud)

结果:

Title
------------------------------
The Ancient Alligator
Aunt Annie's Alligator
A Complete Guide to Alligators
Countrified Alligators
Don't Touch the Alligator!
An Effortless Alligator Hunt
Run Code Online (Sandbox Code Playgroud)