I am trying to run the following as a job on Sql Server Agent
and I don't get an email.
I think there is something wrong with the way I am representing tables in the inner join
because if I replace the query with a simple query without joins, the task works .
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'TEST_DEV',
@recipients = 'xxx@gmail.com',
@query = ' select
Percentage = CONVERT(DECIMAL(10,1),100 - (CAST(COUNT(DISTINCT case when PD.Exception != ' ' then PD.Id END) as float)/CAST(COUNT(PD.Id) as float)*100))
from
DataBaseName.dbo.Product P INNER JOIN DataBaseName.dbo.LogProduct PD
ON P.LogId = PD.LogId
WHERE
ResponseTime < GETDATE() and RequestTime > DATEADD(MINUTE, -150, GETDATE())
' ,
@subject = 'Test',
@attach_query_result_as_file = 1 ;