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
USSC-ITAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.