Missing closing percentage sign to close expression

I need to close the expression near P%-001 do i need to do something different? Works ok as a query!

Also if the query returns no results i want it to skip the email.

Thanks

Keir
EXEC msdb.dbo.sp_send_dbmail
@recipients='keir@advancedventilation.co.uk',
@body='Bonus Reports for Yesterday',
@subject ='Yesterdays Bonus Reports',
@profile_name = 'Keir',
@query ='SELECT T0.CardCode, T0.CardName FROM ORDR T0 WHERE T0.docdate >= (CONVERT(datetime, CONVERT(varchar, GETDATE(), 101)) - 1)
  and T0.docdate < CONVERT(datetime, CONVERT(varchar, GETDATE(), 101))
 and T0.CardCode like 'P%-001'; set nocount off;',
@execute_query_database = 'advanced',
@attach_query_result_as_file = 0,
@query_result_header = 0,
@query_result_width = 1000,
@exclude_query_output = 0,
@query_result_separator = ';'

Open in new window

KeirMcCannAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
you need this:
EXEC msdb.dbo.sp_send_dbmail
@recipients='keir@advancedventilation.co.uk',
@body='Bonus Reports for Yesterday',
@subject ='Yesterdays Bonus Reports',
@profile_name = 'Keir',
@query ='SELECT T0.CardCode, T0.CardName FROM ORDR T0 WHERE T0.docdate >= (CONVERT(datetime, CONVERT(varchar, GETDATE(), 101)) - 1)
  and T0.docdate < CONVERT(datetime, CONVERT(varchar, GETDATE(), 101))
 and T0.CardCode like ''P%-001''; set nocount off;',
@execute_query_database = 'advanced',
@attach_query_result_as_file = 0,
@query_result_header = 0,
@query_result_width = 1000,
@exclude_query_output = 0,
@query_result_separator = ';'

Open in new window

0
 
KeirMcCannAuthor Commented:
thanks angel! so simple when you know how :)
0
All Courses

From novice to tech pro — start learning today.