RJ.*_*RJ. 6 sql t-sql replace substring
表Email:
价值观:
josh@yahoo.com
carmine32@hotmail.com
zehmaneh@yahoo.com
Run Code Online (Sandbox Code Playgroud)
我想之前替换字符串@用test.
结果:
test@yahoo.com
test@hotmail.com
test@yahoo.com
Run Code Online (Sandbox Code Playgroud)
如何根据字符串中的字符使用子字符串和替换?
你甚至不需要使用substring或者replace,你可以使用这个:
SELECT 'test' + RIGHT(email, charindex('@', REVERSE(email)))
FROM YourTable
Run Code Online (Sandbox Code Playgroud)
你可以用这个来测试它:
DECLARE @email nvarchar(50)
SET @email = 'carmine32@hotmail.com'
PRINT 'test' + RIGHT(@email, charindex('@', REVERSE(@email)))
Run Code Online (Sandbox Code Playgroud)