Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Advice on getting an e-mail result sent every day

Author  Topic 

jodders
Starting Member

41 Posts

Posted - 2012-02-24 : 05:31:07
Hi there,

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?

thanks








Any advice would be great :)



USE msdb

EXEC sp_send_dbmail @profile_name='SQL Administrator',

@recipients= 'anon@hotmail.com',
@subject ='Hello World',
@body='How is it going',
--@query = 'select fruit from stall where fruit = apple;'

jodders
Starting Member

41 Posts

Posted - 2012-02-24 : 09:23:50
I have figured it all out, sorry for wasting people's time.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-02-24 : 09:59:36
thats ok...
it would really be great if you can post the final query so that it will make sense for someone reading this thread at a later point.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -