all groups > sql server programming > may 2006 >
You're in the

sql server programming

group:

limiting query result based on AS clause


limiting query result based on AS clause Fabuloussites
5/13/2006 6:42:01 PM
sql server programming: can some point me to a sql statement that would perfrom the equivalent of the
following statement?

select Desc, (select count (*) from CART_Items where
fkItemCategoryID=CART_ItemCategories.pkItemCategoryID ) itemcount
from CART_ItemCategories
where itemcount >0


typical ouput
Desc itemcount
Cat 1 0
Cat 2 2
Cat 3 1
Cat 4 0

Re: limiting query result based on AS clause Fabuloussites
5/13/2006 7:02:01 PM
thanks a million

[quoted text, click to view]
Re: limiting query result based on AS clause Aaron Bertrand [SQL Server MVP]
5/13/2006 9:51:13 PM
SELECT
ic.Desc,
COUNT(ci.fkItemCategoryID)
FROM
Cart_Items ci
INNER JOIN
Cart_ItemCategories ic
ON
ci.fkItemCategoryID = ic.pkItemCategoryID
GROUP BY
ic.Desc
HAVING
COUNT(ci.fkItemCategoryID) > 0;





[quoted text, click to view]

AddThis Social Bookmark Button