September 23, 2021 at 3:52 pm
i have a stored procedure which outputs data from various table query like below.
create procedure ki_data
as
select * from customer
select * from order
select * from invoices
i would like to send the output of stored procedure (in text format) to email .
I know how i can do it using select statement
EXEC msdb.dbo.sp_send_dbmail
@profile_Name ='Administrator',
@recipients='someemail@company.com',
@subject = 'Duplicate PO Lot',
@query = 'SELECT lot, ref_num, ref_line_suf FROM phil_App.dbo.ki_po_dup_lot WHERE prev_lot_used = lot
',
@body = 'Dulicate PO Lot',
@attach_query_result_as_file = 1 ;
END
How do i replace select statement to stored procedure.
September 23, 2021 at 4:12 pm
With the understanding that I've never tried it before, have you tried using EXEC?
--Jeff Moden
Change is inevitable... Change for the better is not.
September 23, 2021 at 5:02 pm
I would use a cursor for each query in a loop and build up the text you want as an nvarchar(MAX) variable.
Then just use the text you have built up as part of the body of the email.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply