?
Solved

Creating a log file from a stored procedure

Posted on 2001-07-10
3
Medium Priority
?
539 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
[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
3 Comments
 
LVL 3

Accepted Solution

by:
trouta earned 400 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

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
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 the fundamental information of how to create a table.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

771 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