[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2008-11-06
9
Medium Priority
?
205 Views
Last Modified: 2012-05-05
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
Comment
Question by:USSC-IT
  • 4
  • 4
9 Comments
 
LVL 12

Accepted Solution

by:
Nathan Riley earned 375 total points
ID: 22897492
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
 
LVL 6

Expert Comment

by:Jerryuk007
ID: 22903955
// 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
 

Author Comment

by:USSC-IT
ID: 22904187
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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 12

Expert Comment

by:Nathan Riley
ID: 22905295
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
 

Author Comment

by:USSC-IT
ID: 22905413
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
 
LVL 12

Expert Comment

by:Nathan Riley
ID: 22905485
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
 

Author Comment

by:USSC-IT
ID: 22905560
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
 

Author Closing Comment

by:USSC-IT
ID: 31514011
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
 
LVL 12

Expert Comment

by:Nathan Riley
ID: 22905666
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Suggested Courses

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question