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
 Execute Stored Procedure

Author  Topic 

Vack
Aged Yak Warrior

530 Posts

Posted - 2014-11-14 : 13:01:14
How can I run my stored procedure called QIVSales inside of this job?
I want the results to be emailed.


Declare @tab char(1) = char(9)
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'AirLift',
@recipients = 'mail@mail.com',
@query = '',
@subject = 'ShippingDollarsbyDay',
@attach_query_result_as_file = 1 ,
@query_attachment_filename = 'ShippingDollarsbyDay.csv',
@query_result_separator=@tab,
@query_result_no_padding=1;

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-11-14 : 13:03:23
Well, msdb.dbo.sp_send_dbmail is a stored procedure!

See how it is run? You can do the same thing
Go to Top of Page

Vack
Aged Yak Warrior

530 Posts

Posted - 2014-11-14 : 13:06:33
Declare @tab char(1) = char(9)
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'AirLift',
@recipients = 'erin@questiv.com',
@query = 'exec([airlift_us].dbo.QIVSalesbyDay15Days)',
@subject = 'ShippingDollarsbyDay',
@attach_query_result_as_file = 1 ,
@query_attachment_filename = 'ShippingDollarsbyDay.csv',
@query_result_separator=@tab,
@query_result_no_padding=1;

Returns this error:
Msg 22050, Level 16, State 1, Line 0
Error formatting query, probably invalid parameters
Msg 14661, Level 16, State 1, Procedure sp_send_dbmail, Line 504
Query execution failed: ?Msg 102, Level 15, State 1, Server SQL, Line 1
Incorrect syntax near 'airlift_us'.
Go to Top of Page

Vack
Aged Yak Warrior

530 Posts

Posted - 2014-11-14 : 13:07:57
I had a typo. I'm good now.

Thanks
Go to Top of Page
   

- Advertisement -