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

前端 未结 4 1166
無奈伤痛
無奈伤痛 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:39

    You don't even need to use substring or replace, you can use this:

    SELECT 'test' + RIGHT(email, charindex('@', REVERSE(email)))
    FROM YourTable
    

    You can test it out with this:

    DECLARE @email nvarchar(50)
    SET @email = 'carmine32@hotmail.com'
    PRINT 'test' + RIGHT(@email, charindex('@', REVERSE(@email)))
    

提交回复
热议问题