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
 how to count a data.

Author  Topic 

immad
Posting Yak Master

230 Posts

Posted - 2014-12-29 : 03:25:08
hi,
my data is like this.

---------code----------------name
ACT706022774CCI0---------CCI
ACT706022774CCI0---------CCI
CDF892782322CCI4---------CCI
CDF892782322CCI4---------CCI
CDF892782322CCI4---------CCI

i want a query that show data like this.

---------code--------------------name
---------ACT ----------------------2
---------CDF-----------------------3

i want to count ACT code and cdf code
thanks for the help.



immad uddin ahmed

sunder.bugatha
Yak Posting Veteran

66 Posts

Posted - 2014-12-29 : 04:13:46
/* select SUBSTRING(code,1,3) as Code ,COUNT(*) as Name from dbo.test1
group by code */

Hema Sunder
Go to Top of Page

MuralikrishnaVeera
Posting Yak Master

129 Posts

Posted - 2014-12-29 : 04:22:56
select DISTINCT SUBSTRING(code,1,3) as Code,COUNT(*)over(PARTITION BY SUBSTRING(code,1,3)) as Name from dbo.#temp

---------------
Murali Krishna

You live only once ..If you do it right once is enough.......
Go to Top of Page
   

- Advertisement -