I need to do a stored procedure that sends an email when a value reaches 100 with this wording in the body: "100 daily file downloaded from the user:USERID" where USERID is the user that reached 100.
I tried this:
EXEC msdb.dbo.sp_send_dbmail
@recipients='MYMAIL',
@body='100 Daily documents downloaded',
@subject ='100 Daily documents downloaded from user',
@query = 'SELECT USERID FROM MYTABLE WHERE MYCOUNTER > ''100'''
I receive this error:
Messaggio 22050, livello 16, stato 1, riga 0 Error formatting query, probably invalid parameters Messaggio 14661, livello 16, stato 1,
procedura sp_send_dbmail, riga 504 Esecuzione della query non
riuscita: Msg 208, Level 16, State 1, Server MYSERVER, Line 1 Invalid
object name 'MYTABLE'.
Best Answer
You have to use
dbname.schema.objectName
e.g.dbname.dbo.MYTABLE
in your tsqlEDIT:
You only want to send email when there are
100 Daily documents downloaded from user
, so you can addNote: Why are you storing integers as chars ? e.g. 100 is stored as
'100'
?