I have a table, Salesperson, and the current name column shows the following:
Undefined - 0
Sam Brett-sbrett
Kelly Roberts-kroberts
Michael Paramore-mparamore
Alivia Lawler-alawler
Ryan Hooker-rhooker
Heather Alford-halford
Cassandra Blegen-cblegen
JD Holland-jholland
Vendor Accounts-VENDOR
Other Accounts-OTHER
Rose Johnson-rjohnson
I've developed the following query to extract the name (minus the ID on the end) with which I want to update this column:
SELECT left(salesperson_name, CHARINDEX('-', salesperson_name) - 1)
FROM Salesperson
------------------------
Undefined
Sam Brett
Kelly Roberts
Michael Paramore
Alivia Lawler
Ryan Hooker
Heather Alford
Cassandra Blegen
JD Holland
Vendor Accounts
Other Accounts
Rose Johnson
I have attempted numerous variations of the following, but get the understandable
Subquery returned more than 1 value...' error.
begin tran
update salesperson
set salesperson_name = (SELECT left(salesperson_name, CHARINDEX('-', salesperson_name) - 1)
FROM Salesperson)
Salespersontable for each row in the table.