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

怎样用一句sql语句或者一个函数将短信发送条数求出来,谢谢!
SELECT SendTels FROM [ZW_User_duanxin] 查出7条记录,其中包含27条短信发送号码。
-----------------------------------------------------------------------
13093680180 18002627928 13093680180 18002627928 18002627928 13093680180 13093680180 18002627928  
10609409076
13093680180 18002627928
13093680180 18002627928
13093680180 18002627928
13093680180 18002627928 13093680180 18002627928  
13093680180 18002627928 13093680180 18002627928 18002627928 13093680180 13093680180 18002627928
-----------------------------------------------------------------------
   
现在怎样用一句sql语句或者一个函数将结果27求出来,谢谢!

------解决方案--------------------
select sum(case when charindex(' ' , SendTels) > 0 then len(SendTels) - len(replace(SendTels,' ','')) else 1 end) from ZW_User_duanxin
------解决方案--------------------
SELECT sum(len(replace(SendTels ,' ',''))/11
FROM [ZW_User_duanxin]
------解决方案--------------------
SQL code
create table tb(SendTels varchar(100))
insert into tb values('13093680180 18002627928 13093680180 18002627928 18002627928 13093680180 13093680180 18002627928')
insert into tb values('10609409076')
insert into tb values('13093680180 18002627928')
insert into tb values('13093680180 18002627928')
insert into tb values('13093680180 18002627928')
insert into tb values('13093680180 18002627928 13093680180 18002627928')
insert into tb values('13093680180 18002627928 13093680180 18002627928 18002627928 13093680180 13093680180 18002627928')
go

select sum(case when charindex(' ' , SendTels) > 0 then len(SendTels) - len(replace(SendTels,' ','')) + 1 else 1 end) from tb

drop table tb

/*
            
----------- 
27

(所影响的行数为 1 行)
*/

------解决方案--------------------
SQL code
if OBJECT_ID('tb') is not null
drop table tb
go
create table tb(SendTels varchar(100))
insert into tb values('13093680180 18002627928 13093680180 18002627928 18002627928 13093680180 13093680180 18002627928')
insert into tb values('10609409076')
insert into tb values('13093680180 18002627928')
insert into tb values('13093680180 18002627928')
insert into tb values('13093680180 18002627928')
insert into tb values('13093680180 18002627928 13093680180 18002627928')
insert into tb values('13093680180 18002627928 13093680180 18002627928 18002627928 13093680180 13093680180 18002627928')
go

select sum(
case when charindex(' ' , SendTels) > 0 then len(SendTels) - len(replace(SendTels,' ','')) + 1  else 1 end
) 
from tb




-----------
27

(1 行受影响)

------解决方案--------------------
SQL code
if OBJECT_ID('tb') is not null
drop table tb
go
create table tb(SendTels varchar(100))
insert into tb values('13093680180 18002627928 13093680180 18002627928 18002627928 13093680180 13093680180 18002627928')
insert into tb values('10609409076')
insert into tb values('13093680180 18002627928')
insert into tb values('13093680180 18002627928')
insert into tb values('13093680180 18002627928')
insert into tb values('13093680180 18002627928 13093680180 18002627928')
insert into tb values('13093680180 18002627928 13093680180 18002627928 18002627928 13093680180 13093680180 18002627928')
go

select sum(
 CEILING( LEN(SendTels)/12.00)
 ) 
from tb



---------------------------------------
27

------解决方案--------------------
select sum(
 CEILING( LEN(SendTels)/12.00)
 ) 
这个经典~~~
探讨

SQL code
if OBJECT_ID('tb') is not null
drop table tb
go