• I know this is old, but I needed a refresher and came across this. I've found it's better not to do the query in the sendmail. Export the file like this:

    Execute xp_cmdshell 'SQLCMD -S VSQL2 -d urdatabase -U urname -P urpassword -Q "Select * from urfilename" -o C:\urexportedfile.csv -W -w 1500 -s","'

    then just do the sendmail with an attachment- no query needed:

    EXEC msdb.dbo.sp_send_dbmail

    @profile_name = 'urSQLemailprofile',

    @recipients = 'anyone@anywhere',

    @subject = 'blah blah blah',

    @body = 'more blah ',

    @file_attachments= 'C:\urexportedfile.csv'

    End

    If your Windows Default Programs are set for Excel to open .csv files, it will open purty as you please.

    Wallace Houston
    Sunnyland Farms, Inc.

    "We must endeavor to persevere."