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 2000 Forums
 SQL Server Development (2000)
 Excel attachment with DBMail

Author  Topic 

vgr.raju
Yak Posting Veteran

95 Posts

Posted - 2006-11-13 : 17:25:55
HI All,
I am using dbmail feature to send the Query results to email recipients. Query results are attached as Text attachment as default.
Is there any way I can make file extension as Excel attachment.
Help would be much appreciated.

I am using the following code:
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'Raju',
@recipients = 'raju.venkataraman@test.com,
@query = 'SELECT * FROM Northwind.dbo.customers' ,
@subject = Nothing,
@attach_query_result_as_file = 1 ;

I am able to send the excel attachment using the following code.
XP_cmdshell 'bcp.exe -Q"Query" -o C:\Filepath.xls -c -T'.
and then attach the output file with email But the output file is not formatted properly.That causes the problem.

Any help would be really appreciated.


Thanks!
Raju
http://www.trickylife-trickylife.blogspot.com/

bhaskar.rm
Starting Member

6 Posts

Posted - 2009-09-10 : 04:57:56
XP_cmdshell 'bcp.exe -Q"Query" -o C:\Filepath.xls -c -T'.

i Cannot be able to execute this code..

It showing Error


Copy direction must be either 'in', 'out' or 'format'.
usage: bcp.exe {dbtable | query} {in | out | queryout | format} datafile
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n native type] [-c character type] [-w wide character type]
[-N keep non-text native] [-V file format version] [-q quoted identifier]
[-C code page specifier] [-t field terminator] [-r row terminator]
[-i inputfile] [-o outfile] [-a packetsize]
[-S server name] [-U username] [-P password]
[-T trusted connection] [-v version] [-R regional enable]
[-k keep null values] [-E keep identity values]


Bhaskar
Go to Top of Page

bhaskar.rm
Starting Member

6 Posts

Posted - 2009-09-10 : 05:00:53
I used simple select query!

Bhaskar
Go to Top of Page
   

- Advertisement -