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)
 how to count Categories using stored procedure

Author  Topic 

mrtanvirali
Starting Member

41 Posts

Posted - 2009-04-11 : 03:26:00
I've Categories in Category table and some rows in other table, i want to fetch the following result,

Category 1 (4) items
Category 2 (12) items

etc.

mrtanvirali
Starting Member

41 Posts

Posted - 2009-04-11 : 03:49:10
its done, i've used group by clause to get the desired result,
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2009-04-11 : 04:42:09
hi try like below

select count(*) as items, s.categoryid from category s inner join items p
on s.categoryid =p.categoryid group by s.categoryid

ok tanx
Go to Top of Page

mrtanvirali
Starting Member

41 Posts

Posted - 2009-04-11 : 04:49:56
thanks for reply sooraj,
i've already done,

this link helped me (http://www.sqlteam.com/article/how-to-use-group-by-in-sql-server)
Go to Top of Page

soorajtnpki
Posting Yak Master

231 Posts

Posted - 2009-04-11 : 04:53:54
ok

welcome....
Go to Top of Page
   

- Advertisement -