Thanks for reply.. I have changed the script for email notification as below and sending email number of records not to be zero
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 wanting the number of records to not be zero
If ((select count(*) from #results) <> 0)
Begin
EXEC msdb.dbo.sp_send_dbmail @profile_name='db_mail',
@recipients='ananad.murugesan@ril.com',
@subject='Alert!-Verify Instance',
@query='select * from #results'
End
drop table #tableA
drop table #tableB
drop table #results