Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Email ID formatting

Author  Topic 

abhishek_kumar_rch
Starting Member

6 Posts

Posted - 2014-11-29 : 03:30:23
Hi,
There is email address in my datablse table column as username
I have to select it from database in such a way so that first two letter and last
two letters only visible before @
for example this email id (sontosh_kumar_rch@yahoo.com) should be selected in below format..
sontosh_kumar_rch@yahoo.com

sa...............ch@yahoo.com

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-11-29 : 11:37:52
1. use CHARINDEX to find the @ character
2. use the result of 1 to split the email into two parts: name and domain
3. For the name. take LEFT(name, 2) + replicate('.', len(name) -4) + right(name, 2)
4. add @ and the domain name to the end of the new name
Go to Top of Page

MuralikrishnaVeera
Posting Yak Master

129 Posts

Posted - 2014-12-01 : 09:21:39
[code]
DECLARE @var varchar(max) = 'santosh_kumar_rch@yahoo.com'
SELECT REPLACE(@var,SUBSTRING(@var,3,PATINDEX('%@%',@var)-5),'------')
[/code]

---------------
Murali Krishna

You live only once ..If you do it right once is enough.......
Go to Top of Page
   

- Advertisement -