|
Hi, How to get the following result.Basically i am trying to get the domain name from the emailaddress. expected result is:
(comments are locked)
|
|
Something like this should do it: The idea is to select a part of the string beginning from the character after the @ and pick the number of characters equal to the position of @ minus potition of the dot minus 1. To be on the safe side, it would be better to handle the situation when the name part of email contains dots, which is possible. For example, if you have an entry bozo.theclown@circus.net then this entry will break the original query I posted, so it would be better to enhance it a bit by limiting the search for a dot position to begin after the @ has already been found, i.e. Onle last touchup: the charindex('@', EmailAddress) is repeated 3 times, so it might be worth it to consider outsourcing the activity to the CTE, so the script looks a bit cleaner: The last version is probably not going to be any faster than the second one, it just looks a little bit cleaner. Oleg Thanks Oleg. It works perfect. But what if i have an email address like 'ab.c@gmail.com'. How does we take care of this situation too?
Dec 09 '10 at 12:15 PM
swethaashwini
@swetha There are 2 scripts in my answers, the second one addresses the issue. I typed my answer too fast, this is why the original query did not account for this scenario.
Dec 09 '10 at 12:19 PM
Oleg
Thanks Oleg, this is what i was exactly looking for.
Dec 09 '10 at 12:28 PM
swethaashwini
(comments are locked)
|
|
Oleg's answer is fine. Here's just a little variation I tried out of curiosity. I gave it a few tweaks to cope with anomalous (incorrect) addresses
(comments are locked)
|


@swethaashwini: if @Oleg answer was helpful and solves your problem please mark it as answer so that others will find the solution quickly int he future.