sql-servert-sqlstored-proceduresdatabase-mail

got an error on an procedure, sql send mail not working


so, i have this code, for a procedure. the code is below:

EXEC msdb.dbo.sp_send_dbmail  
    @profile_name = 'SQL-PHC',  
    @recipients = 'filipeferreira@mass.pt',  
    @query = 'SELECT no, nome, obrano, convert(varchar,datafinal)  
    FROM bo
    WHERE nmdos LIKE "Preços por Cliente"
    AND datafinal = DATEADD(day, -1, CONVERT(date, GETDATE()))' ,  
    @subject = 'Work Order Count',  
    @attach_query_result_as_file = 1 ;

when i parse the code, everything is ok, but when i execute it i get the following error:

Msg 22050, Level 16, State 1, Line 0
Failed to initialize sqlcmd library with error number -2147467259.

i really don't get whats wrong or how to solve this


Solution

  • well, finally got it right. after using profiler i discovered the error was on the query, so just adding the database name to the "from" solved it. thanks anyway guys