0

I have a table with all employee details including email addresses

Is there any specific query via which I can find the length of the email addresses till the letter '@' is encountered?

if the email address is azxcde@asas.com, then I want to extract the azxcde part of the email.

Phil
  • 157,677
  • 23
  • 242
  • 245
Naga
  • 141
  • 1
  • 12

2 Answers2

6
Select 
Left(EmailColumnName,CharIndex('@',EmailColumnName)-1) as UserName 
from tableName

SQL Fiddle Demo

Amit Singh
  • 8,039
  • 20
  • 29
1

Here is an alternative version using SUBSTRING:

SELECT SUBSTRING(EmailColumnName,0,CHARINDEX(' ',EmailColumnName)) as UserName
FROM tablName
Craig T
  • 2,761
  • 5
  • 25
  • 33