Sql 将名称的中间值移到其他列中

Sql 将名称的中间值移到其他列中,sql,sql-server,Sql,Sql Server,我一直在努力将MS SQL server中的一些名称拆分成几列,剩下的是姓氏和中间值(Smithson的约翰) 下面是我想做的,我有几个例子: of Holland Of the Clothson, England, from 我有3个变量,可以在字符串中的任意位置。我要做的是从LastName列中删除这些值,并将它们移动到中间列,这样我就可以 LastName|Amidst -------------- Holland |of clothson|of the England |from

我一直在努力将MS SQL server中的一些名称拆分成几列,剩下的是姓氏和中间值(Smithson的约翰)

下面是我想做的,我有几个例子:

of Holland
Of the Clothson, 
England, from
我有3个变量,可以在字符串中的任意位置。我要做的是从LastName列中删除这些值,并将它们移动到中间列,这样我就可以

LastName|Amidst
--------------
Holland |of
clothson|of the
England |from

最好的方法是什么?是否可以将要选择的值移动到表中并从表中引用?我不确定这是否可行。

根据您的描述,giant
case
表达式可能是最好的方式:

select (case when col like '% of the%'
             then ltrim(rtrim(replace(col, ' of the', '')))
             when col like '% of%'
             then ltrim(rtrim(replace(col, ' of', '')))
             when col like '% from%'
             then ltrim(rtrim(replace(col, ' from', '')))
             else col
        end) as new_col,
       (case when col like '% of the%'
             then 'of the'
             when col like '% of%'
             then 'of'
             when col like '% from%'
             then 'from'
        end) as new_midst

我希望它不会局限于这三个,如果有一个helper表并从中工作会更好吗?