表Email
:
値:
josh@yahoo.com
carmine32@hotmail.com
zehmaneh@yahoo.com
@
前の文字列を。に置き換えたいtest
。
結果:
test@yahoo.com
test@hotmail.com
test@yahoo.com
文字列内の文字に基づいてサブストリングを使用して置換するにはどうすればよいですか?
substring
またはを使用する必要はありませんreplace
。これを使用できます。
SELECT 'test' + RIGHT(email, charindex('@', REVERSE(email)))
FROM YourTable
あなたはこれでそれをテストすることができます:
DECLARE @email nvarchar(50)
SET @email = 'carmine32@hotmail.com'
PRINT 'test' + RIGHT(@email, charindex('@', REVERSE(@email)))
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
結果:
Test@yahoo.com
Test@hotmail.com
Test@yahoo.com
あなたは出来る
select 'test' + substring(fld, charindex('@', fld), len(fld))