I love it.... and coincidentally I was working in the same problem but from a Powershell angle. Now I don't have to.
BTW... why do you have this:
your your WHERE statement:
andjob.name not in ('Database Mirroring Monitor Job', '<dbname>')
Is that left over from testing?