首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

怎样用一句sql语句或者一个函数将短信发送条数求出来,多谢

2012-08-17 
怎样用一句sql语句或者一个函数将短信发送条数求出来,谢谢!SELECT SendTels FROM [ZW_User_duanxin] 查出7

怎样用一句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')goselect sum(case when charindex(' ' , SendTels) > 0 then len(SendTels) - len(replace(SendTels,' ','')) + 1 else 1 end) from tbdrop table tb/*            ----------- 27(所影响的行数为 1 行)*/
[解决办法]
SQL code
if OBJECT_ID('tb') is not nulldrop table tbgocreate 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')goselect 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 nulldrop table tbgocreate 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')goselect 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


create table tb(SendTels varchar(100))
insert into tb values('13093680180 18002627928 13093680180 18002627928 18002627928 13093680180 1309368……

热点排行