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)
 Query-Help Urgent

Author  Topic 

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2009-10-14 : 07:29:41
Hi all,
Lets say i have tbl as follows:

Id name

1 A,B
2 A
3 C,A
4 B,C,A
5 A

Like Abv tbl,"A" has repeated 5 times.i need a query to find out A how many times to be repeated in the table.pl help me how to do this.

cipriani1984
Constraint Violating Yak Guru

304 Posts

Posted - 2009-10-14 : 08:00:31
lets give this a go

select sum(a_count) AS a_finalcount
from (
select id, name, case when (name like '%a%') THEN 1 else 0 end as a_count
from table_name
) AS A

is this what your after? Gives you just a count of how many times A appears on whole table.

quote:
Originally posted by haroon2k9

Hi all,
Lets say i have tbl as follows:

Id name

1 A,B
2 A
3 C,A
4 B,C,A
5 A

Like Abv tbl,"A" has repeated 5 times.i need a query to find out A how many times to be repeated in the table.pl help me how to do this.

Go to Top of Page
   

- Advertisement -