At the moment, I am experimenting how to use the sp_send_db_mail library and managed to get a very basic e-mail sent to me which means I am on the right track to get where I want to be. The trouble is I am having trouble entering in my select statement which I would like to add into the @Query part. The one below is a very basic example, but I think my syntax is wrong as that doesn't work either!
I have a select statement that I have prepared already, and was hoping to just copy and paste it in but I don't think it's that simple?
I have already set up a job under SQL Server Agent to run the below query, just need to figure how to insert my Select statement (which has a few joins! in to the @query part.
(*Update*) - i figured out why my simple query did not work, it's because I didn't specify the database I before the table name. School boy error.
What is the correct syntax if I have many joins and I am giving an individual table a name?
Any advice would be great :)
EXEC sp_send_dbmail @profile_name='SQL Administrator',
@subject ='Hello World',
@body='How is it going',
--@query = 'select fruit from stall where fruit = apple;'