我有桌子客户:
Name
David Smith
John David
Jonathan Greg
我希望将其转移到表Customers2:
Name Surname
David Smith
John David
Jonathan Greg
如何将这些名称拆分为姓名/姓氏?
谢谢
答案 0 :(得分:2)
也许这只是一个空间更好的分裂者......
Create table customers2 (
SELECT PARSENAME(REPLACE(Name, ' ', '.'), 2) AS [FirstName],
PARSENAME(REPLACE(Name, ' ', '.'), 1) AS [LastName]
FROM Customers)
答案 1 :(得分:1)
假设它是严格的名字+姓氏,你可以这样做
SELECT PARSENAME(REPLACE('David Smith', ' ', '.'), 1) AS NAME,
PARSENAME(REPLACE('David Smith', ' ', '.'), 1) AS SURNAME