This question already has answers here:
Using T-SQL, return nth delimited element from a string (14 answers)
Closed 3 days ago.
I'm trying to query data from a column that has 3 values separated by " | " as a delimiter. I'm having trouble trying to extract the second value without creating an additional column
Example of data:
{cookie_data}
732711 | 732711@soundcorp.com | 732711 Store
I want to get the email portion only.
SELECT
SUBSTRING(cookie_data, CHARINDEX(' | ', cookie_data) + 3, LEN(cookie_data)) AS login_data,
SUBSTRING(login_data, 0, CHARINDEX(' | ', login_data)) AS email,
FROM TABLE
While this solution works, I was curious if there was an easier way of doing this without generating an extra column that isn't needed other than to create the final substring.
1条答案
按热度按时间gjmwrych1#
you can use string_split instead of substring but I wrote with two ways(substring without New Column,string_split )
1.Get Email(with PAttern):
2.Get Email(with order):
3.Get Email(with Substring):
Result: