Solved

Creating a log file from a stored procedure

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

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.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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…
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.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

777 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