Solved

Creating a log file from a stored procedure

Posted on 2001-07-10
3
537 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
ID: 6270373
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
ID: 6270398
This worked great.

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

Expert Comment

by:trouta
ID: 6270454
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
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 …

730 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