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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Advice on getting an e-mail result sent every day
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

United Kingdom
41 Posts

Posted - 02/24/2012 :  05:31:07  Show Profile  Reply with Quote
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?


Any advice would be great :)

USE msdb

EXEC sp_send_dbmail @profile_name='SQL Administrator',

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

Edited by - jodders on 02/24/2012 06:06:26

Starting Member

United Kingdom
41 Posts

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

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 02/24/2012 :  09:59:36  Show Profile  Reply with Quote
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

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000