• gouri92 (11/29/2014)


    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..

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

    Quick code snip, should get you passed this hurdle

    😎

    DECLARE @EMAIL_STR VARCHAR(30) = 'sontosh_kumar_rch@yahoo.com';

    SELECT

    @EMAIL_STR AS NORMAL_EMAIL

    ,STUFF(@EMAIL_STR,3, (CHARINDEX('@',@EMAIL_STR,1) - 5),REPLICATE(CHAR(46),(CHARINDEX('@',@EMAIL_STR,1) - 5))) AS DOTTED_EMAIL

    ;

    Results

    NORMAL_EMAIL DOTTED_EMAIL

    ------------------------------ ------------------------------

    sontosh_kumar_rch@yahoo.com so.............ch@yahoo.com