Solved

Creating a log file from a stored procedure

Posted on 2001-07-10
3
532 Views
Last Modified: 2013-11-18
I need to process some records (in a stored procedure) and then write some stats to a log file.

In this test, I get screen results but the testit.txt file is not created. any ideas?

CREATE PROCEDURE [orgfile] AS
declare @msg as Char(255)
DECLARE @var sysname, @cmd sysname
SET @Msg = "this is a test"
SET @cmd = 'echo ' + @msg + ' -o  d:\testit.txt'
EXEC master..xp_cmdshell @cmd
0
Comment
Question by:pmacmann
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
trouta earned 100 total points
Comment Utility
Try this

CREATE PROCEDURE [orgfile] AS
declare @msg Char(255)
DECLARE @var sysname, @cmd varchar(255)
SET @Msg = 'this is a test'
SET @cmd = 'echo ' + rtrim(@msg) + ' > d:\testit.txt'
EXEC master..xp_cmdshell @cmd
0
 

Author Comment

by:pmacmann
Comment Utility
This worked great.

Shouldn't the -o and the > work the same?
0
 
LVL 3

Expert Comment

by:trouta
Comment Utility
I don't know, I have never seen the -o switch used before, and I don't see it in the help.  The other problem was the @msg variable had 255 blank characters and was overfilling the @cmd variable.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now