|
Posted by Paul Spratley on 02/14/06 12:23
Hi all
Firstly this my first time posting to technical groups - so any
mistakes I apologise for in advance.
I am trying to count records in several secondary tables for the same
run in a primary table. However, there might be no records in these
secondary tables for the specific run. Hence the sql below returns
nulls.
Select run, (select count(errors) from table2 where run = t1.run group
by run) as errors, (select count(user) as users from table3 where run =
t1.run and user = active group by run, dd)
from table1 t1
(Please note the different group bys. )
I do not want nulls to be returned but to be replaced with 0. I have
tried the isnull function but this does not work. eg
Select run, (select isNull(count(errors),0) from table2 where run =
t1.run group by run) as errors, (select isNull(count(user),0) as users
from table3 where run = t1.run and user = active group by run, user)
from table1 t1
Nor will isnull work if I put it around the select clause.
Any suggestions?
Thanks for the help!
Navigation:
[Reply to this message]
|