0

我有下表:

InventorLast    InventorFirst
Bram            Ernst Arne Johan
Gesing          Ernst Rudolf F.
Beranek         Ernst W.
Koch            Ernst-Christian
Bozak           Erol
Kurtas          Erozan Mehmet
Calder          Errol Jay
Binder          Erwin
Goetschi        Erwin

我想在第一个空格或 - 如 Ernst-Christian 示例中看到的分隔中间名/首字母。

在创建表之后或从源数据插入时,我会更容易执行此操作吗?

现有的插入顺序如下:

insert into Inventor (PatentNo, InventorFirst, InventorLast, City, statename, country, NationalityCountry, ResidenceCountry)
select PatentNo, InventorFirstname, InventorLastname, City, statename, country, NationalityCountry, ResidenceCountry
from InventorUpdate
where InventorFirstName is not null 
and InventorLastName is not null

我知道我将不得不添加 InventorMiddle 列。我只需要一些编码方面的帮助。

谢谢!

4

1 回答 1

1

rather ugly,but...

Think you just didn't say what to do when there's just a "no space no - name"

select substring(InventorFirst, 0, (case when  
                 patindex('%[ -]%', InventorFirst) = 0
                 then len(InventorFirst) + 1
                 else patindex('%[ -]%', InventorFirst)
                 end)
                 ) as middleValue,
       case 
         when patindex('%[ -]%', InventorFirst) = 0
          then '' 
          else substring(InventorFirst, 
                         patindex('%[ -]%', InventorFirst)+1, 
                         len(InventorFirst))
       end as endValue 
                 from inventor

http://sqlfiddle.com/#!3/57fa7/20

于 2012-07-20T15:24:57.960 回答