try this:
DECLARE @YourTable table (RowValue varchar(50))
INSERT @YourTable VALUES ('1234abc')
INSERT @YourTable VALUES ('1234abcde456757')
INSERT @YourTable VALUES ('1234abc Supervisor')
INSERT @YourTable VALUES ('1234abc456 Administrator')
UPDATE @YourTable
SET RowValue=LEFT(RowValue,4)+RIGHT(RowValue,CHARINDEX(' ',REVERSE(RowValue)))
FROM @YourTable
SELECT * FROM @YourTable
OUTPUT:
RowValue
--------------------------------------------------
1234
1234
1234 Supervisor
1234 Administrator
(4 row(s) affected)
EDIT: set based any number of digits and handles no digits or no words
DECLARE @YourTable table (RowValue varchar(50))
set nocount on
INSERT @YourTable VALUES ('13')
INSERT @YourTable VALUES ('1234abc')
INSERT @YourTable VALUES ('1234abc')
INSERT @YourTable VALUES ('1234abcde456757')
INSERT @YourTable VALUES ('1234abc Supervisor')
INSERT @YourTable VALUES ('1234abc456 Administrator')
INSERT @YourTable VALUES ('1234567abc456 Administrator')
INSERT @YourTable VALUES ('Administrator')
INSERT @YourTable VALUES ('abcde Administrator')
set nocount off
;WITH Digits AS
(SELECT 0 AS Digit UNION SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 UNION SELECT 7 UNION SELECT 8 UNION SELECT 9
)
,Numbers AS
(SELECT 1 AS Number
UNION ALL
SELECT Number+1 FROM Numbers where Number<1000
)
,FindDigits AS
(
SELECT
y.RowValue,n.Number,SUBSTRING(y.RowValue,n.Number,1) AS CharOf,CASE WHEN SUBSTRING(y.RowValue,n.Number,1) LIKE '[0-9]' THEN 'N' ELSE 'A' END AS TypeOf
FROM @YourTable y
INNER JOIN Numbers n ON 1=1
WHERE n.Number<=LEN(y.RowValue)
)
,LenOf AS
(
SELECT
RowValue,MIN(Number)-1 AS Digits
FROM FindDigits
WHERE TypeOf='A'
GROUP BY RowValue
HAVING MIN(Number)-1>0
UNION
SELECT
f.RowValue,LEN(f.RowValue)
FROM FindDigits f
WHERE NOT EXISTS (SELECT 1 FROM FindDigits f2 WHERE f.RowValue=f2.RowValue AND TypeOf='A')
)
UPDATE y
SET RowValue=CASE WHEN l.Digits IS NOT NULL THEN LEFT(y.RowValue,l.Digits)+RIGHT(y.RowValue,CHARINDEX(' ',REVERSE(y.RowValue)))
WHEN CHARINDEX(' ',REVERSE(y.RowValue))=0 THEN y.RowValue
ELSE RIGHT(y.RowValue,CHARINDEX(' ',REVERSE(y.RowValue))-1) END
FROM @YourTable y
LEFT JOIN LenOf l ON y.RowValue=l.RowValue
OPTION (MAXRECURSION 1000)
SELECT * FROM @YourTable
OUTPUT:
RowValue
--------------------------------------------------
13
1234
1234
1234
1234 Supervisor
1234 Administrator
1234567 Administrator
Administrator
Administrator
(9 row(s) affected)