SELECT substr(Emails, instr(Emails, '@')+1)
FROM EmployeeEmails;
Returns
gmail.com
Do I need to concat to get:
gmail
SELECT substr(Emails, instr(Emails, '@')+1)
FROM EmployeeEmails;
Returns
gmail.com
Do I need to concat to get:
gmail
Check your relevant database query :
Query(for MySQL)
select (SUBSTRING_INDEX(SUBSTR(Emails, INSTR(Emails, '@') + 1),'.',1)) from EmployeeEmails;
Query(For Sql Server):
select SUBSTRING(Emails,(CHARINDEX('@',Emails)+1),1) from EmployeeEmails;
Query(For Oracle)
select substr(Emails,instr(Emails,'@',1)+1) as domain
from EmployeeEmails;
You can use REGEXP_REPLACE to extract the domain name:
select regexp_replace(emails, '^[^@]+@([^.]+)\..+$', '\1') from employeeemails;
This works for any email of the pattern abcd@efgh.ijkl .
The pattern:
^ start of the sting [^@]+ 1 to n characters other than @@ the at sign @( remember the following string[^.]+ 1 to n characters other than the dot .) end of the string to remember\. a dot ..+ 1 to n characters$ end of the string\1 the remembered stringAnd here is the old-fashioned way without REGEXP_REPLACE:
select substr(emails,
instr(emails, '@') + 1,
instr(emails, '.', instr(emails, '@') + 1) - instr(emails, '@') - 1
)
from employeeemails;
You can use LIKE with wild cards see here
percent sign character (%) for a string of zero or more characters.
SELECT email FROM emails
WHERE email NOT LIKE '%_@__%.__%'
This will ignore the following cases (simple version for valid emails):
try this : -
declare @email sysname = 'testCode@gmail.com'
SELECT substring(@email, charindex('@',@email,0)+1 , (charindex('.',@email,0)-1 - charindex('@',@email,0)))