Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 find out the phone number

Author  Topic 

balbal
Starting Member

1 Post

Posted - 2009-03-18 : 19:28:27
hi I have got a table with 10records with telephone number for December. in these numbers, few of them start with 01, 02 (normal number) and the special num start with 08. so what I need is, I want to find out total number of calls made to normal numbers, and the difference between the special number and normal number calls. can anyone please help me to find this out?

thanks

singularity
Posting Yak Master

153 Posts

Posted - 2009-03-18 : 19:47:53
select count(case when left(phone, 2) in ('01','02') then phone end) as normal_count,
count(case when left(phone, 2) in ('01','02') then phone end) -
count(case when left(phone, 2) = '08' then phone end) as difference
from your_table
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-19 : 12:54:33
[code]select sum(case when left(phone, 2) in ('01','02') then 1 else 0 end) as normal_count,
sum(case when left(phone, 2) in ('01','02') then 1 else -1 end) as difference
from your_table
where left(phone, 2) in ('01','02','08')
[/code]
Go to Top of Page
   

- Advertisement -