I do not have access to write to a database, queries are limited to retrieval only. CTEs are not allowed. Cannot write functions. (Here's a document of what I'm limited to https://help.salesforce.com/articleView?id=mc_as_sql_reference.htm&type=5)
Here's an example of a string I'm working with, I'm looking to extract the email address, where I consistently know that the email will begin at the fourth |, and end at the fifth |.
D||John Smith|EML|test@gmail.com|Y|2014/01/03 17:14:01.000000|
This is what I tried so far, it's not able to return any email addresses for me
SELECT
CASE
WHEN CHARINDEX('|',AllData) > 0
THEN SUBSTRING(AllData, CHARINDEX('|', AllData, 22) + 1, ABS((CHARINDEX('|', AllData, CHARINDEX('@', AllData))) - (CHARINDEX('|', AllData, 22) + 1)))
ELSE 'NotWorking'
END AS email
FROM
[test_file]