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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KeirMcCannAuthor Commented:
thanks angel! so simple when you know how :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.