How do I replace a substring of a string before a specific character?

前端 未结 4 1147
無奈伤痛
無奈伤痛 2021-01-02 19:50

Table Email:

Values:

josh@yahoo.com
carmine32@hotmail.com
zehmaneh@yahoo.com

I want to replace the string before

4条回答
  •  再見小時候
    2021-01-02 20:27

    declare @t table(email varchar(30))
    insert @t values('josh@yahoo.com'),
                    ('carmine32@hotmail.com'),
                    ('zehmaneh@yahoo.com') 
    
    select stuff(email, 1, charindex('@', email), 'Test@') 
    from @t
    

    Result:

    Test@yahoo.com
    Test@hotmail.com
    Test@yahoo.com
    

提交回复
热议问题