I am trying to split a single string containing multiple email address data into three variables. The strings mark the start/end of an email address with the ; character.
An example string would be:
'joebloggs@gmailcom;jimbowen@aol.com;dannybaker@msn.com'
The code I currently have for this is as follows:
DECLARE @Email VARCHAR(100),
@Email2 VARCHAR(100),
@Email3 VARCHAR(100)
SET @Email = 'joebloggs@gmailcom;jimbowen@aol.com;dannybaker@msn.com'
SET @Email2 = SUBSTRING(@Email, CHARINDEX(';', @Email)+1, LEN(@Email))
SET @Email3 = SUBSTRING(@Email, CHARINDEX(';', @Email)+1, LEN(@Email))
SET @Email = SUBSTRING(@Email, 1, CHARINDEX(';', @Email)-1)
Unfortunately this doesn't seem to work. Could someone please point out where I am going wrong and what I should do to fix my problem?
Thanks in advance.