I forgot an ELSE... look at »
codepad.org/NGlABcACYou can add more logic if you don't want ANY invlaid domains being returned, even when max node count is greater than 0.
But like PetePuma
said, there is no catch all for this. Some of it is going to have to be implementation specific.