We help IT Professionals succeed at work.
Get Started

problem with db_mail

Fairfield asked
Last Modified: 2012-05-08
I have a procedure that attaches the result of a query to an email, however the attachment is not the same of the select statement.  Can someone offer suggestions why this is happening or provide an alternate solution?

The results of the select statement is:

Material Number      Business Group
123456                  IPG  
123456-001  234567      IPG  
123456-001              ESS  

however the attachment with the results is different (see attached file)
EXEC msdb.dbo.sp_send_dbmail
@body='Message Body', 
@subject ='Message Subject',
@profile_name ='ROHS_Profile',
@query = 'SELECT     CAST(ISNULL([Material Number], '') AS CHAR(18)) AS [Material Number], CAST(ISNULL([Business Group], '') AS char(6)) AS [Business Group]
@attach_query_result_as_file = 1,
@query_attachment_filename ='Results.txt'

Open in new window

Watch Question
This problem has been solved!
Unlock 1 Answer and 39 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE