SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 sending output of a proc using xp_sendmail
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

igorblackbelt
Constraint Violating Yak Guru

USA
407 Posts

Posted - 03/27/2008 :  16:33:50  Show Profile  Click to see igorblackbelt's MSN Messenger address  Reply with Quote
The scenario:
An SP that will create a temp table (#table) with users with access to an specific app.
One of the last steps on the SP is: SELECT * FROM #Results
Is it possible to use that output from the SP and send that in a .csv file to a list of people using xp_sendmail?

I was told that modifying the SP is not an option, otherwise I could add the xp_sendmail at the end of the procedure.

spirit1
Cybernetic Yak Master

Slovenia
11741 Posts

Posted - 03/27/2008 :  16:39:26  Show Profile  Visit spirit1's Homepage  Reply with Quote
create table #Temp_Results (columns of the same type as those that SP returns)
insert into #Temp_Results
exec yourSP

do what you want with data from #Temp_Results here


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
35007 Posts

Posted - 03/27/2008 :  16:50:03  Show Profile  Visit tkizer's Homepage  Reply with Quote
Can't you specify EXEC StoredProcName for @query in xp_sendmail? I seem to recall using stored procedures with SQL Mail, but it's been a while as we're on SQL 2005 and using Database Mail instead.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

igorblackbelt
Constraint Violating Yak Guru

USA
407 Posts

Posted - 03/27/2008 :  17:01:02  Show Profile  Click to see igorblackbelt's MSN Messenger address  Reply with Quote
Tara,
Yes I can, that's a good thing that I wasn't aware of, I thought you could only pass select results to the @query parameter.

But it didn't really work for my purpose, the SProc has tons of print statements and all of that is getting appended to my .csv file, which I can't have, I only need the results from the #Resutls table which is created and populated towards the end of the SP. I'm going to have to either modify the proc or create a whole new one.
Go to Top of Page

spirit1
Cybernetic Yak Master

Slovenia
11741 Posts

Posted - 03/27/2008 :  17:08:17  Show Profile  Visit spirit1's Homepage  Reply with Quote
and my suggestion doesn't work for you why?

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

igorblackbelt
Constraint Violating Yak Guru

USA
407 Posts

Posted - 03/27/2008 :  17:14:36  Show Profile  Click to see igorblackbelt's MSN Messenger address  Reply with Quote
No, it didn't work because of the tons of print statements that I have on the SP, it would work perfectly if I didn't have those print statements... Makes sense?
Go to Top of Page

spirit1
Cybernetic Yak Master

Slovenia
11741 Posts

Posted - 03/27/2008 :  17:33:43  Show Profile  Visit spirit1's Homepage  Reply with Quote
print statements are irrelevant:

create proc spTest
as
print 'begin proc'
select 1 as c1, 2 as c2, 'ffdsgds' as c3
print 'end proc'
go

exec spTest

create table #temp(c1 int, c2 int, c3 varchar(10))
insert into #temp
exec spTest

-- you put this query in your xp_sendmail
select * from #temp

drop table #temp
drop proc spTest


_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
SSMS Add-in that does a few things: www.ssmstoolspack.com
Go to Top of Page

igorblackbelt
Constraint Violating Yak Guru

USA
407 Posts

Posted - 03/31/2008 :  14:23:47  Show Profile  Click to see igorblackbelt's MSN Messenger address  Reply with Quote
I created a new SP, changed the #table to be an ##table and used the table on the xp_sendmail.

Spirit,
I made a note of your solution, which I'll try next time.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.09 seconds. Powered By: Snitz Forums 2000