Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to convert a table into a text ???

Status
Not open for further replies.

pitt1

Programmer
Dec 25, 2005
13
GB
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 a stored procedure for that,

thanks a lot,
Pitter
 
Lookup xp_sendmail in BOL
below are 2 examples

C. Send results
This example sends the results of the sp_configure to Robert King.

EXEC xp_sendmail 'robertk', @query = 'sp_configure'

D. Send results as an attached file
This example sends the results of the query SELECT * FROM INFORMATION_SCHEMA.TABLES as a text file attachment to Robert King. It includes a subject line for the mail and a message that will appear before the attachment. The @width parameter is used to prevent line breaks in the output lines.

EXEC xp_sendmail @recipients = 'robertk',
@query = 'SELECT * FROM INFORMATION_SCHEMA.TABLES',
@subject = 'SQL Server Report',
@message = 'The contents of INFORMATION_SCHEMA.TABLES:',
@attach_results = 'TRUE', @width = 250



Denis The SQL Menace
SQL blog:
Personal Blog:
 
thnks man ! u saved me few hours...
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
 
you could use DTS to create an excel file and attach that
The problem will be if the file is larger than 3MB, most email system will reject such a 'big' file
A better way would be (if it's inside a company) create the file and in the email give the network path to that file

Denis The SQL Menace
SQL blog:
Personal Blog:
 
can you please be more specific..after creating the .xls
file, what is the tsql procedure i should run ??

regards,
pitter
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top