Advertisement

11.07.2006 at 08:57PM PST, ID: 22052848
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.8

Passed a file to a stored procedure and would like to e-mail as attachment

Asked by Data-Man in MS SQL Server

Tags: , , , ,

Hi all,
    There is a stored proc that has a parameter of type image (this parameter is streamed in using ADO).  They are small PDF's.  The files are inserted into a table.  No problem.

    The proc then creates an e-mail and sends out the file as an attachment.  I ended up having to use the TextCopy command to output the file from the table to a file on the hard drive before I could attached it.  

    My question is this:  Is is possible to attach the file without first writing it to the hard drive?  If not, I'm worried about concurrency issues with the procedure using a static path and file name.

    Here is the procedure:

------------------------------------------
ALTER           PROCEDURE pfrmProcessPayrollIndividualStoreAndEmailPDF
(
      @intPID                        INT                      =1,
      @datStartDate                  DATETIME                      ='10-28-2006',
      @datEndDate                  DATETIME                      ='11-04-2006',
      @strDatabaseReportName                      VARCHAR(50)      ='Testing',
      @strReportCategory                            VARCHAR(50)      ='Payroll',
      @strEmail                        VARCHAR(50)      ='Testing@Testing.com',
      @imgFile                        IMAGE            =0x0,
      @intFileSize                  INT                      =0,
      @strFileName                  VARCHAR(50)      ='Testing.pdf',
      @strPW                        VARCHAR(20)            ='Testing'
)
AS

DECLARE @strSubject            NVARCHAR(100)
DECLARE @strExec            VARCHAR(500)
DECLARE @strSSFileName      VARCHAR(50)

--Step 1, Insert data into the table
INSERT INTO tblEmployeeEmailedReports
                  (PID, StartDate, EndDate, EmailAddress, DatabaseReportName, ReportCategory, FileImage, FileSize, FileSystemName)
      VALUES (@intPID, @datStartDate, @datEndDate,@strDatabaseReportName,@strReportCategory,@strEmail,@imgFile,@intFileSize,@strFileName)


--Step 2,  Save the image to the file system
SELECT @strExec = 'C:\Progra~1\Micros~1\MSSQL\Binn\textcopy.exe /S /U ' + SYSTEM_USER
SELECT @strExec = @strExec + ' /P ' + @strPW + ' /D DatabaseName /T tblEmployeeEmailedReports /C FileImage '
SELECT @strExec = @strExec + '/W "WHERE EmailReportID=' + CAST(@@IDENTITY AS VARCHAR) + '" /F c:\Payroll.pdf /O'
--SELECT @strExec

EXEC master..xp_cmdshell @strExec


--Step 3, Send the report via e-mail
SET @strSubject = N'Payroll report from ' +
      cast(datepart(mm, @datStartDate) as nvarchar(2)) + '-' +
      RIGHT('0' + cast(datepart(dd, @datStartDate) as nvarchar(2)),2) + '-' +
      cast(datepart(yyyy, @datStartDate) as nvarchar(4))
      + ' To ' +
      cast(datepart(mm, @datEndDate) as nvarchar(2)) + '-' +
      RIGHT('0' + cast(datepart(dd, @datEndDate) as nvarchar(2)),2) + '-' +
      cast(datepart(yyyy, @datEndDate) as nvarchar(4))

SET @strSSFileName = N'C:\Payroll.pdf'
            EXEC master.dbo.xp_smtp_sendmail
                        @TO = @strEmail,
                        @FROM = N'Testingr@Testing.com',
                           @subject = @strSubject,
                           @message = N'Please find the attached report.',
                        @server = N'MySMTPServer,
                        @attachments = @strSSFileName,
                        @port = 25
--------------------------
Thanks in advance for your help and thoughts.

Mike

   Start Free Trial
[+][-]11.08.2006 at 03:48PM PST, ID: 17902817

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: attach, xp_smtp_sendmail, file, procedure, stored
Sign Up Now!
Solution Provided By: acperkins
Participating Experts: 1
Solution Grade: A
 
 
[+][-]11.08.2006 at 05:13PM PST, ID: 17903106

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11.08.2006 at 05:39PM PST, ID: 17903239

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11.08.2006 at 07:12PM PST, ID: 17903799

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-44