Incorrect syntax in sp_send_dbmail

  • EXEC msdb.dbo.sp_send_dbmail

    @recipients = 'EMAIL REMOVED',

    @subject = 'Something Important',

    @query = 'select * from TableName where Source = 1 and (name like '%I%' or '%O%')',

    @attach_query_result_as_file = 1,

    @profile_name = 'sqldba',

    @body_format = 'HTML'

    I m getting, Incorrect syntax near '%' . Can some one help me out in this??

    Thanks a lot..

  • do you mean?

    EXEC msdb.dbo.sp_send_dbmail

    @recipients = 'EMAIL REMOVED',

    @subject = 'Something Important',

    @query = 'select * from TableName where Source = 1 and (name like '%I%' or name like '%O%')',

    @attach_query_result_as_file = 1,

    @profile_name = 'sqldba',

    @body_format = 'HTML'

  • ssismaddy (10/16/2009)


    EXEC msdb.dbo.sp_send_dbmail

    @recipients = 'EMAIL REMOVED',

    @subject = 'Something Important',

    @query = 'select * from TableName where Source = 1 and (name like '%I%' or '%O%')',

    @attach_query_result_as_file = 1,

    @profile_name = 'sqldba',

    @body_format = 'HTML'

    I m getting, Incorrect syntax near '%' . Can some one help me out in this??

    Thanks a lot..

    I think you need to double up the single quotes. I can't test this so if it doesn't work let me know.

    EXEC msdb.dbo.sp_send_dbmail

    @recipients = 'EMAIL REMOVED',

    @subject = 'Something Important',

    @query = 'select * from TableName where Source = 1 and (name like ''%I%'' or ''%O%'')',

    @attach_query_result_as_file = 1,

    @profile_name = 'sqldba',

    @body_format = 'HTML'

  • Thanks eveyone for your replies...It worked with the 2 single quotes

    Thank you Matt...

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply