表Email
:如何在特定字符前替换字符串的子字符串?
值:
[email protected]
[email protected]
[email protected]
我想test
@
之前更换的字符串。
结果:
[email protected]
[email protected]
[email protected]
如何使用substringing和基于字符串中的字符替换?
表Email
:如何在特定字符前替换字符串的子字符串?
值:
[email protected]
[email protected]
[email protected]
我想test
@
之前更换的字符串。
结果:
[email protected]
[email protected]
[email protected]
如何使用substringing和基于字符串中的字符替换?
你甚至都不需要使用substring
或replace
,您可以使用此:
SELECT 'test' + RIGHT(email, charindex('@', REVERSE(email)))
FROM YourTable
你可以用这个测试出来:
DECLARE @email nvarchar(50)
SET @email = '[email protected]'
PRINT 'test' + RIGHT(@email, charindex('@', REVERSE(@email)))
你可以
select 'test' + substring(fld, charindex('@', fld), len(fld))
+1有比选择的更好的答案 –
UPDATE Email set email =
'test' + SUBSTRING(email, CHARINDEX('@',email), LEN(email))
declare @t table(email varchar(30))
insert @t values('[email protected]'),
('[email protected]'),
('[email protected]')
select stuff(email, 1, charindex('@', email), '[email protected]')
from @t
结果:
[email protected]
[email protected]
[email protected]
+1我总是忘记'STUFF'。 –
你使用任何服务器端语言? – Breezer