SQL select to get a string between two spaces

后端 未结 3 887
借酒劲吻你
借酒劲吻你 2021-01-06 23:02

I have a field with names in the format DOE JOHN HOWARD or DOE JOHN H.

I need a query to get the string between the two spaces (JOHN in this case).

The SO an

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-06 23:32

    One way:

    select 
    left(substring(fld, 
        charindex(' ', fld) + 1, len(fld)), 
        charindex(' ', substring(fld, charindex(' ', fld) + 2, len(fld)))) 
    

提交回复
热议问题