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
Solved

Creating a log file from a stored procedure

Posted on 2001-07-10
3
536 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
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 INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
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…

860 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