2012-04-05 114 views

回答

6
select len('[email protected]') - len(replace('[email protected]', '.', '')) 
+0

它不会把它们都算在内 – 2012-04-05 11:01:30

+0

@RoyiNamir:你说得对。目前尚不清楚OP的要求。单独计数或添加它们。 – 2012-04-05 11:04:47

1

这会给你想要的结果。

DECLARE @str VARCHAR(1000) 
SET @str = '[email protected]_df.com' 
SELECT (LEN(@str)- LEN(REPLACE(@str ,'.' ,'')))+(LEN(@str)- LEN(REPLACE(@str ,'_' ,''))) 

回答:5

0

如果要算的是有两个._行数,你可以做到以下几点:

select count(*) 
    from mytable 
where left(email, charindex('@', email)) like '%[._]%[._]%' 

leftcharindex用于忽略域名(其将具有.)。

参考:LIKE (TSQL, SQL Server 2008)

1

我认为他想的@前计数不点的字母:

declare @myEmail varchar(50) 
set @myEmail = '[email protected]' 

declare @mySearch varchar(50) 
set @mySearch = SUBSTRING (@myEmail,0 , PATINDEX('%@%',@myEmail)) 
select (LEN(REPLACE(@mySearch, '.', ''))) 
相关问题