none
EXEC msdb.dbo.sp_send_dbmail

    Question

  • Hi,

    I am trying to run a job that creates a file then it sends an email to me showing me the link to the file.

    The first step runs fine but i am getting the the following error message when it trys to send the email:

    Executed as user: HDWA\Hin-sqlagt2008. Incorrect syntax near '@body'. [SQLSTATE 42000] (Error 102).  The step failed.

    My Code looks like this:

    DECLARE @file nvarchar(max)
    SET @file = N'C:\HSIU\SSRS Jobs\HSIU\FH Admissions From RKHSAKHS ' + convert(varchar(10), GETDATE(), 120) + '.pdf';
    EXEC msdb.dbo.sp_send_dbmail
        @profile_name = 'HSIU DW ADMIN',
        @recipients = 'HE110235@health.wa.gov.au',
        @subject = 'Fremantle Admissions from Rockingham and Armadale'
        @body = '\\wsfm146sql\HSIU\FH Admissions From RKHSAKHS';

    Any help appreciated
    Friday, May 24, 2013 1:38 AM

Answers

  • Try the below:(You missed a comma between body and subject)

    DECLARE @file nvarchar(max)
    SET @file = N'C:\HSIU\SSRS Jobs\HSIU\FH Admissions From RKHSAKHS ' + convert(varchar(10), GETDATE(), 120) + '.pdf';
    EXEC msdb.dbo.sp_send_dbmail
        @profile_name = 'HSIU DW ADMIN',
        @recipients = 'HE110235@health.wa.gov.au',
        @subject = 'Fremantle Admissions from Rockingham and Armadale',
        @body = '\\wsfm146sql\HSIU\FH Admissions From RKHSAKHS';


    Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.

    • Marked as answer by lrj1985 Friday, May 24, 2013 1:56 AM
    Friday, May 24, 2013 1:43 AM