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
 General SQL Server Forums
 New to SQL Server Programming
 query needed

Author  Topic 

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-11-10 : 08:16:53
hi all,
i have a customers table storing tel,mobile,worktel numbers.

now i need a query which pull up customers that do not have a minimum of 2 phone numbers..
these 3 column can get null values too.
pls help

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-10 : 08:24:42
[code]
select customer from
(
select *,
case when tel<>'' then 1 else 0 end+case when mobile<>'' then 1 else 0 end+case when worktel<>'' then 1 else 0 end as counting
from table
) as t
where counting<2
[/code]


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

malaytech2008
Yak Posting Veteran

95 Posts

Posted - 2008-11-10 : 08:29:10
How do u storing phone numbers,if it is different table having phone number only
then I think it work..

select p.cust_id from phone p inner join customer c
on c.cid=p.cid group by cust_id having count(cust_id)>=2

malay
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2008-11-10 : 09:08:38
thanks madhivanan
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-11-10 : 09:20:41
quote:
Originally posted by soorajtnpki

thanks madhivanan


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -