2012-04-05 118 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, '.', ''))) 
相關問題