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 a sql server2000 table by mail

Author  Topic 

pitt1
Starting Member

16 Posts

Posted - 2006-02-20 : 04:42:28
Hi folks,

I'm a novice in sql server, I would like to
know how to convert a table into a text, that is,
i actually want to send a table by mail, and i think i can't really send the table itself, i have to convert it into text,i'll appreciate if someone can show how to write the stored procedure for that,

thanks a lot,
Pitter

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-02-20 : 04:45:14
pitt1, Welcome to SQLTeam.

"how to convert a table into a text"
You can use BCP or DTS to export a table to text file

You can refer to Books Online for details.

Also refer to http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=Sending,SMTP,Mail
for sending mail from t-sql
----------------------------------
'KH'

Time is always against us
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2006-02-20 : 05:02:07
you can also use a sproc on Vyas' website that will generate the insert statements for your table using standard SQL.

http://vyaskn.tripod.com/code.htm#inserts

this might be easier to use than a file created with BCP.



-ec
Go to Top of Page

pitt1
Starting Member

16 Posts

Posted - 2006-02-20 : 10:21:41
thnks guys,
i used the following stored procedure:

EXEC master.dbo.xp_sendmail @recipients = email@loc.com',
@query = 'SELECT * FROM pubs.pite1.tblDATA',
@subject = 'SQL Server Report',
@message = 'The contents of INFORMATION_SCHEMA.TABLES:',
@attach_results = 'TRUE', @width = 250

i have encountered couple of problems,
1. if the table is quite big, i'm getting this
message from the server :
"Server: Msg 18025, Level 16, State 1, Line 0
xp_sendmail: failed with mail error 0x80004005"
if i'm selecting less rows it works just fine

2. how can i send the table as an excel sheet ?
and not just as a text..

regards,
pitter
Go to Top of Page

jhermiz

3564 Posts

Posted - 2006-02-20 : 11:36:29
Have you looked at xp_sendmail ?
You can send query outputs via emails as .csv files.


Keeping the web experience alive -- [url]http://www.web-impulse.com[/url]

RS Blog -- [url]http://weblogs.sqlteam.com/jhermiz[/url]
Go to Top of Page

pitt1
Starting Member

16 Posts

Posted - 2006-02-20 : 14:02:41
yes i looked at xp_sendmail...
i still geting this mesage from the server:

Server: Msg 18025, Level 16, State 1, Line 0
xp_sendmail: failed with mail error 0x80004005"

i think its because the table is just too big...(if i'll selecet less less rows it
will work just fine)
any suggestions ??

Regards,
pitter
Go to Top of Page
   

- Advertisement -