Link to home
Start Free TrialLog in
Avatar of USSC-IT
USSC-IT

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Nathan Riley
Nathan Riley
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
// 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
Avatar of USSC-IT
USSC-IT

ASKER

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.
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....
Avatar of USSC-IT

ASKER

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.
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.
Avatar of USSC-IT

ASKER

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.
Avatar of USSC-IT

ASKER

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.
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.