Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SP Counting 1

Status
Not open for further replies.

free47

Programmer
Jun 9, 2008
10
US
I am trying to make a stored proc that will count the number of times each company comes up. Here is an example of my data set.

Company | ID
1 25
1 25
2 26
3 27
3 27
3 27

I want the final result of the query to be :

Company | count
1 2
2 1
3 3

Is this possible in SQL?

Thanks in advance! :)
 
Sure:
Code:
SELECT Company,
       COUNT(*) AS Cnt
FROM YourTable
GROUP BY Company

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top