• I read the thread from your original post, and so far the emphasis has been on finding alternatives to LEFT and RIGHT, but your original question was just about the ability to nest LEFT and RIGHT to achieve one particular kind of result. So I just wanted to answer your actual question, and the answer is unequivocally "yes, you can nest LEFT and RIGHT." It may not be as flexible as the other "solutions" offered, but it can be done and if your data is rigid enough to have only two delimiters in it -- two periods, say, or one @ and one period -- then it can do exactly what you describe.

    I'm going to "steal" the MyData CTE text from the earlier post in the thread, but then I'd like to share two solutions: one for extracting a domain from a URL and one for extracting a domain from an email address. The "trick," if there is one, is that you have to use the calculation of one of the options twice inside the second one. In the examples I use the RIGHT calculate twice inside the LEFT calculation: once to stand in for the primary "string" to be manipulated by the LEFT function, and a second time as the string to be manipulated by the CHARINDEX() function to locate the second delimiter.

    Here is the solution for URL, using a period as the delimiter for both left and right:

    with MyData(url) as

    (

    select 'http://www.google.com' union all

    select 'https://www.google.com' union all

    select 'www.google.com' union all

    select 'www.google.info' union all

    select 'www.google.mobi' union all

    select 'www.google.de'

    )

    select

    url,

    left(right(url, len(url) - charindex('.', url)), charindex('.', right(url, len(url) - charindex('.', url)))-1) as extract

    from MyData;

    And here is the solution for the email address, using @ as the delimiter on the left and a period as the delimiter on the right:

    with MyData(email) as

    (

    select 'an.email@google.com' union all

    select 'another.email@google.com' union all

    select 'yetathirdemail@google.com' union all

    select 'fourthemail@google.info' union all

    select 'fifthtest@google.mobi' union all

    select 'sixth@google.de'

    )

    select

    email,

    left(right(email, len(email) - charindex('@', email)), charindex('.', right(email, len(email) - charindex('@', email)))-1) as extract

    from MyData

    Hope this helps address your original question, and perhaps assist with your secondary concern about extracting well-formed information out of malformed email addresses.