Saturday 11 December 2021

Extract the domain name form email id

We have a requirement like that to extract the domain name from the email id. For Example  my email id is Bageshkumarbagi@gmail.com  then domain name will be gmail.com.

With the help of SUBSTRING &  CHARINDEX we can extract the domain name.

See the below domain.

declare @tbl as table

(

Email_id varchar(100)

)

insert into @tbl (Email_id)

select 'bagesh@gmail.com' union all

select 'abc@hkjgyui.com' union all

select 'bagesh.singh@coforge.com' union all

select 'bagesh.singh@atos.com'

 

SELECT

    Email_id,

    SUBSTRING(

        Email_id,

        CHARINDEX('@', Email_id)+1,

        LEN(Email_id)-CHARINDEX('@', Email_id)

    ) Domain

FROM

   @tbl

ORDER BY

    Email_id;

Get the expected result.



No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts