日期:2014-05-18 浏览次数:20640 次
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 行) */
------解决方案--------------------
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 行受影响)
------解决方案--------------------
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)
)
这个经典~~~