• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

Need to generate a file and e-mail it from a SQL stored procedure

Hi, all - we're using a SQL based ERP system and need to generate a file for use with our banks' positive pay system. I'm a bit of a SQL novice - I've been able to put together a decent stored procedure that culls the data I need from our ERP system, but don't have the slightest clue what to do with it next. What I need to do is generate a flat text file (fixed width output - not delimited) with the contents of the SQL query and e-mail that file to the specified recipient.

Any help is appreciated!

Adam
0
USSC-IT
Asked:
USSC-IT
  • 4
  • 4
1 Solution
 
Nathan RileyFounderCommented:
I would create a DTS package.  Or If your using 2005 then a SSI package to run your stored procedure then push it to a .txt file on the hard drive.
0
 
Jerryuk007Commented:
// Have you set-up SQLMail on your server or are you planning to use CDO ?

For you text file, you could insert all the desired data into a temporary table then bcp it out ?

Crystal Report could be also an alternative...

Jerry
0
 
USSC-ITAuthor Commented:
Crystal does not appear to be an option... when it exports to text, it still maintains some formatting. I need this to be pure fixed width with no white spaces. The receiving system for this file is an older COBOL system.

My problem with SSIS is that I've never used it before, although I've gotten a hacked package created. I need to figure out how to pass variables to the stored procedure that generates the output.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Nathan RileyFounderCommented:
You don't have to generate it that way.  After your SP runs have it create a destination txt file.  On the left side of the screen where all the objects are it's called a Flat File Destination.  In there you can decide what type of delimiters that you want ect....
0
 
USSC-ITAuthor Commented:
I think I see - what you are saying is to run the SP without delimiting it, and then let the SSIS package select based on input criteria. Where does the user interaction occur, though? Do you create a front end for the package?

I should have been a little more specific - at the run time for the procedure, it is passed a date and a bank number, provided by the end user. It wouldn't be a problem for scheduled check runs but I do need to allow for mid-week check runs for rush, high priority checks.
0
 
Nathan RileyFounderCommented:
Yes, and what I mean is put the SP in the SSIS package.  On the left you will see Execute SQL task.  Use that and direct it to the SP.  Then drag the green line from the Execute SQL task to your Flat File Destination.  That way as soon as the SP completes it will put it to a file.  And if you need it to run certain times then you can schedule it or if it needs to be ran for a rush then you can just execute the package on your own.
0
 
USSC-ITAuthor Commented:
Thanks. That makes sense - I was combining your suggestion with an example from another site... I'd pasted the code for the SP in to the SSIS itself. I'll give this a shot.
0
 
USSC-ITAuthor Commented:
Makes sense. Accurate solution. Left details as an exercise for the student.  I'd really give it an A-, not a B. I need to learn how to do this, so this is better. If someone else did it for me, I'd never learn how to use SSIS.
0
 
Nathan RileyFounderCommented:
Yeah if it doesn't work exactly how you want feel free to send it over and I can take a look at the structure of it for you and send it back.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now