I have a table (in SQL Server) that has 2 columns. One column contains multiple server names separated with a tilda ~. This column could or could not contain the actual server name. The other column has the actual server name.
I am looking for a way to separate the first column values into their own separated column. The number of aliases range from 1 to ?.
Server_Alias_Names Actual_Server_Name
------------------------------------------------------------
Server1~ROSCO24~Server3~Server4~~~~~ ROSCO24
STEVETESDB26~~~~~~~~~ STEVETESDB26
RALPHPRD117~RALPHPRD117-adm~Server0025~Server0025a1~Server0025a2~Server0025a3~~~~~ RALPHPRD117
Server1001~Server1001R1~Server1001-adm~~~~~~~ DBTEST1001
I have the first two servers extracted from the string, I am having trouble on the next few. Any help is appreciated!!!
SELECT
LEFT(Server_Alias_Names, CHARINDEX('~', Server_Alias_Names) - 1) as 'First_Server',
SUBSTRING(Server_Alias_Names,len(LEFT(Server_Alias_Names, CHARINDEX('~', Server_Alias_Names)+1)),LEN(LEFT(Server_Alias_Names, CHARINDEX ('~', Server_Alias_Names)))) as 'Second_Server'
FROM
TBL_NAME