It's realy hard to understand what you are after here is it the 'Diff' can not be zero to send email or if number of rows returned is not zero then send email?
This is just my problem with doing sub queries, so I broke it down to se what is going on.
select MACHINE, COUNT(*) as Instance
into #tableA
from PROD.dbo.CM_INSTANCE
group by MACHINE
Select COUNT(*)/4 as InstanceA
into #tableB
from PROD.dbo.CM_INSTANCE
Select A.MACHINE, A.Instance, B.InstanceA,
(B.InstanceA-A.Instance) as Diff
into #results
from #tableA A,
#tableB B
where (B.InstanceA-A.Instance) < -3 or (B.InstanceA-A.Instance) > 3
-- If you are you trying to see if the 'Diff' is not zero to send email
If ((select Diff from #results) <> 0)
Begin
End
-- If you are wanting the number of records to not be zero
If ((select count(*) from #results) <> 0)
Begin
End
-------------------------------------------------------------
we travel not to escape life but for life not to escape us
Don't fear failure, fear regret.