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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Sql Query to Excel to Email

Author  Topic 

besadmin
Posting Yak Master

116 Posts

Posted - 2009-07-20 : 15:37:38
Hey Friends.

I have basically a SELECT statement already created. I need to run the query and have it populate an Excel Spreadsheet. Then I want to Email the spreadsheet as an attachment. I would like to do this via a stored procedure that is called by a scheduled job in SQL. I think I can do the Email part using xp_smtp_sendmail and just attach the spreadsheet. But getting the data from the query into the spreadsheet is where I need help.

Any assistance is greatly appreciated!

Thanks so much!

-S

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-07-20 : 16:06:41
Check this link. I think it has everything you need.

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926
Go to Top of Page

besadmin
Posting Yak Master

116 Posts

Posted - 2009-07-20 : 16:41:31
That doesnt look too bad. I think method number 5 is closest to what I want to do. The problem is I dont have a table. I want to use a temp table or something, only the select at that time.

Do you know of any full examples anywhere I can check out?

Thanks a lot for the reply!!

-S
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-21 : 02:40:55
quote:
Originally posted by besadmin

That doesnt look too bad. I think method number 5 is closest to what I want to do. The problem is I dont have a table. I want to use a temp table or something, only the select at that time.

Do you know of any full examples anywhere I can check out?

Thanks a lot for the reply!!

-S


What happens when you use global temporary table?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

besadmin
Posting Yak Master

116 Posts

Posted - 2009-07-21 : 10:59:19
I am not sure yet. I need help with method 5 from the earlier link. I see how you pass in the database, table, and file name, but I am not sure about all those other variables. What do I replace what with? and Where do I put my SQL query?

Also, if I succeed at using method #5, am I then able to send that Excel file as an attachment using xp_smtp_sendmail?

Thanks a lot for your help!

And anyone else who wants to join in!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-22 : 02:12:40
In @table_name, assign the name of the global temporary table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

besadmin
Posting Yak Master

116 Posts

Posted - 2009-07-23 : 14:45:15
Hey! I just wanted to say I got it working using a global temp table and method #5 from the linked post above.

Thanks a lot for everyones replys!
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-07-24 : 02:55:55
quote:
Originally posted by besadmin

Hey! I just wanted to say I got it working using a global temp table and method #5 from the linked post above.

Thanks a lot for everyones replys!


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -