Home Forums SQL Server 2005 T-SQL (SS2K5) parsing variable into @query using sp_send_dbmail RE: parsing variable into @query using sp_send_dbmail

  • As far as I know, you aren't going to generate a native Excel file from a SQL procedure.  The closest I've been able to come is a .csv file, but that's not native Excel - it's just opened by Excel on most PCs.  The primary purpose of sp_send_dbmail procedure is to send email.  It can also include query results as an attachment, but can also include a file from disk.

    In theory, if you generate your output file on disk, convert it to Excel and then use sp_send_dbmail to send it, it should work.  However, I know of no way to generate an Excel file from within a stored procedure.  I'd think that to do so, you'd need to have Excel installed on the server and then use sp_oacreate to instantiate it, but I've never tried.  Then again, I wouldn't even install Excel on a SQL Server.