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
 How to send email using msdb.dbo.sp_send_dbmail

Author  Topic 

swims01
Yak Posting Veteran

59 Posts

Posted - 2009-05-19 : 13:17:29
Hey all. I'm running SQL 2005 and have set up SQL Mail successfully. I can send a test email through SQL's test email function and it works fine.

I'm using a query within my job but I don't know how to reference the correct database.

EXEC msdb.dbo.sp_send_dbmail
@recipients=N'me@me.com',@body='Message Body',
@subject ='Message Subject',@profile_name ='Nightly Emails',
@query='select * from mydb.tblmembers'

My database is 'mydb' but I'm not sure what goes in front of that. Like... msdb.something.mydb.tblmembers

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-19 : 13:20:56
it should be
select * from mydb.<yourschema>.tblmembers
Go to Top of Page

swims01
Yak Posting Veteran

59 Posts

Posted - 2009-05-19 : 13:30:31
Thanks, as usual, visakh16 =)

How can I find out what my schema is?
Go to Top of Page

swims01
Yak Posting Veteran

59 Posts

Posted - 2009-05-19 : 13:33:11
never mind. i got it. thanks again!!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-05-19 : 13:39:45
welcome
Go to Top of Page
   

- Advertisement -