Keerthi
Keerthi

Reputation: 1

how to get string after special character(@) in SQL

I have mail address and i want to save the domain name.How to fetch.

Upvotes: 0

Views: 1941

Answers (3)

saravanatn
saravanatn

Reputation: 630

In Sql Server:

substring(mail,charindex('@',mail)+1,len(mail))

Upvotes: 0

AT-2017
AT-2017

Reputation: 3149

Have you tried the following:

select
substring_index(ColName, '@', -1)
from table

Upvotes: 2

Gordon Linoff
Gordon Linoff

Reputation: 1270401

In MySQL, you would use substring_index(). To get the string after the last (or only) '@', you would use:

select substring_index(str, '@', -1)
from t;

In SQL Server, one method would look like:

select substring(col, charindex('@', col + '@') + 1, len(col))
from t;

Note that if there is no '@', then this returns an empty string.

Upvotes: 1

Related Questions