?
Solved

SQL job output to a Text file

Posted on 2013-06-14
4
Medium Priority
?
2,534 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
5teveo earned 1000 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 25

Assisted Solution

by:chaau
chaau earned 1000 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 25

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard 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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

752 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