I've a table with entries like this.
MachineName
-----------------------
Ab bb zecos
a zeng
zeng
empty
4 rows in a table.
How can i seperate those 4 rows to get output like.
M1 M2 M3
-----------------------------------
Ab bb zecos
a zeng NULL
zeng NULL NULL
NULL NULL NULL
Instead of using split function there is a function called ParseName which returns the specified part of the object which spilts the string delimated by . Please go through the ParseName link which helped me in writing this query
Declare @Sample Table
(MachineName varchar(max))
Insert into @Sample
values
('Ab bb zecos'),('a Zeng')
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]
FROM (Select MachineName from @Sample
) As [x]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With