PARSENAME (Transact-SQL) Returns the specified part of an object name. The parts of an object that can be retrieved are the object name, owner name, database name, and server name. The PARSENAME function does not indicate whether an object by the specified name exists.
use YOUR_DB
Declare @Sample Table
(MachineName varchar(max))
Insert into @Sample
values
('Ab bb zecos mm'),('a Zeng')
select * from @Sample
SELECT
Reverse(ParseName(Replace(Reverse(MachineName), ' ', '.'), 1)) As [M1]
, Reverse(ParseName(Replace(Reverse(MachineName), ' ', '.'), 2)) As [M2]
, Reverse(ParseName(Replace(Reverse(MachineName), ' ', '.'), 3)) As [M3]
,Reverse(ParseName(Replace(Reverse(MachineName), ' ', '.'), 4)) As [M4]
FROM (Select MachineName from @Sample
) As [x]
In figure first one is Input table and second one is Output Table :
No comments:
Post a Comment