I've got a query that counts the results of a subselect. It works great when my subselect returns rows, but if my subselect returns nothing, the count portion doesn't return anything. I'm trying to get it to still return what I need, just with 0's populating the output instead of whatever the count would be. I know the problem is that the count portion has nothing to select from when the subquery returns nothing, so I think I just need the subquery to return populate relcust regardless of if it doesn't fund any results.Here's my query:SELECT Coalesce(COUNT(*), '0') AS prodcount, relcust, Datename(MONTH, transdate) AS MONTH, Datepart(MONTH, transdate) AS monthnum, Datename(YEAR, transdate) AS YEAR FROM (a long subselect that has the possibility of returning 0 rows. when it returns rows, it returns relcust, transdate, and a field that tracks each transaction (this is what the count is done on)) AS tmp GROUP BY relcust, Datename(MONTH, transdate), Datepart(MONTH, transdate), Datename(YEAR, transdate) ORDER BY relcust, YEAR DESC, monthnum DESC
output results if the subquery does return results:prodcount relcust month monthnum year 1 pers1 aug 8 2010 2 pers2 aug 8 2010 3 pers3 aug 8 2010
these would be the results of the subquery:transname relcust transdate abc pers1 8/6/2010 abc1 pers2 8/1/2010 abc2 pers2 8/5/2010 def1 pers3 8/10/2010 def2 pers3 8/15/2010 def3 pers3 8/20/2010