2012-09-11 9 views
6

Email特定の文字の前に文字列の部分文字列を置き換えるにはどうすればよいですか?

値:

[email protected] 
[email protected] 
[email protected] 

私はtest@前に文字列を置換します。

結果:

[email protected] 
[email protected] 
[email protected] 

どのように私はsubstringingを使用して、文字列内の文字をもとに置き換えるのですか?

+0

あなたが任意のサーバーサイド言語を使用していますか? – Breezer

答えて

5

あなたも、あなたがこれを使用することができ、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))) 
+0

nice!ありがとう! :) – Testifier

+1

@Testifierすべてのソリューションを試しましたか? –

+0

すべてではなく、この1つだけです。 – Testifier

1

あなたは可能性があり

select 'test' + substring(fld, charindex('@', fld), len(fld)) 
+0

+1より良い答えを持っているために+1 –

関連する問題