日期:2014-05-18  浏览次数:20436 次

高手指教,Sql语句如何让email部分带有星号
select uEmail from table

henyabc@hotmail.com
wcchfae@163.com
bono@hello.com


如何让显示的Email带有星号


heny***@hotmail.com
wcch***@163.com
bono***@hello.com

谢谢了

------解决方案--------------------
SQL code

select uEmail=replace(uEmail,substring(uEmail,5,3),'***') from table

------解决方案--------------------
SQL code
DECLARE @T TABLE (uEmail NVARCHAR(50))
INSERT @T SELECT 'henyabc@hotmail.com'
INSERT @T SELECT 'wcchfae@163.com'
INSERT @T SELECT 'bono@hello.com'


SELECT 
CASE WHEN  CHARINDEX('@',uEmail)<5 THEN LEFT(uEmail,CHARINDEX('@',uEmail)-1) ELSE LEFT(uEmail,4) end+'***'+RIGHT(uEmail,CHARINDEX('@',REVERSE(uEmail))) AS uEmail

FROM @T

/*
heny***@hotmail.com
wcch***@163.com
bono***@hello.com
*/

------解决方案--------------------
探讨

引用:

SQL code
DECLARE @T TABLE (uEmail NVARCHAR(50))
INSERT @T SELECT 'henyabc@hotmail.com'
INSERT @T SELECT 'wcchfae@163.com'
INSERT @T SELECT 'bono@hello.com'


SELECT
LEFT……

------解决方案--------------------
探讨

引用:

SQL code
DECLARE @T TABLE (uEmail NVARCHAR(50))
INSERT @T SELECT 'henyabc@hotmail.com'
INSERT @T SELECT 'wcchfae@163.com'
INSERT @T SELECT 'bono@hello.com'


SELECT
LEFT……