Solved

SQL job output to a Text file

Posted on 2013-06-14
4
1,912 Views
Last Modified: 2013-06-21
Hello All,
How can I
Output messages in text file produced by SQL Server 2008 job .
Appreciate any thoughts.
0
Comment
Question by:Star79
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
5teveo earned 250 total points
ID: 39249137
use SQLCMD utility
http://msdn.microsoft.com/en-us/library/ms162773.aspx

sample
command could be...
sqlcmd -i E:\SQLScripts$\Auto\130-100-ESE-Tally\130-100-ESE-Tally.sql c:\OutputDeleteMe.txt

I placed this command in .BAT file and run as needed via task scheduler or stand alone
0
 
LVL 24

Assisted Solution

by:chaau
chaau earned 250 total points
ID: 39252007
If you do not want to fiddle with the batch files, you can always do it with the job itself. Select a job "Step" that is required to be logged and go to advanced properties. there you will find an option to output the result to a log file. You can also make it "overwrite" the log file, or "append". See the screenshot below
Job Output option
0
 

Author Comment

by:Star79
ID: 39256741
I have created the storeprocedure that extracts the data.Can somebody tell me how to create it as a sql job and it has to out the data to a text file as in the attached file.
How can I put the data on the position as in the file.Not sure if it has to be a job,can I output from the SP to a text file
screenshot.gif
0
 
LVL 24

Expert Comment

by:chaau
ID: 39258061
you can do this very easily with SP and the job. Use PRINT command, I.e.:

PRINT '    Field         Position       Description'
PRINT '   Blank         1-26            Blank'
etc.

This can be put inside a table cursor (if you retrieve these details from a table).
It can also be formatted using STUFF function. The numbers can be formatted using STR function
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 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