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)
 Sql Count

Author  Topic 

cable_si
Starting Member

20 Posts

Posted - 2010-09-19 : 10:48:27
Hi

I am trying to write a query to count all the telephone numbers with a table

The below would return 6

Id Tel1 Tel2 Tel3
1 01214478953 079733939933
2 01212339494 049458585858 01238434934
3 01232345489


Can any one help at all

thanks

Simon

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-09-19 : 11:30:20
[code]
SELECT COUNT(Tel1) + COUNT(Tel2) + COUNT(Tel3)
FROM table
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dineshrajan_it
Posting Yak Master

217 Posts

Posted - 2010-09-20 : 04:14:31

DECLARE @t1 TABLE(Id INT IDENTITY(1,1) NOT NULL, Tel1 bigint, Tel2 bigint, Tel3 bigint)
insert into @t1(Tel1, Tel2, Tel3)
values(01214478953,079733939933,null),
(01212339494,049458585858,01238434934),
(01232345489,null,null)

select * from @t1

select COUNT(1)
from
(
select TelColumn,TelNo
from
@t1
unpivot
(TelNo for TelColumn in ([Tel1],[Tel2],[Tel3])) t)t1

Iam a slow walker but i never walk back
Go to Top of Page
   

- Advertisement -