Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools


This stored procedure accepts a message, filename, overwrite mode as an input parameters and logs that message to the specified file on the server

Click here to copy the following block
CREATE PROC Log_to_file
@msg VARCHAR(100),
@file VARCHAR(100),
@overwrite BIT = 0
AS

/*
 Date written: January 12th 2001
 Purpose: To log messages to text files from stored procedures/triggers/sql scripts
 Input parameters: message, file name, overwrite flag (1 to overwrite, 0 to append to file, 0 is the default)
 Example: EXEC write_to_file 'Duplicates found','C:\logfile.txt',0
 Tested on: SQL Server Version 7.0, 2000
 Remarks: You should have permissions required through access file system through xp_cmdshell
      See SQL Server Books Online for xp_cmdshell if you are having problems with this procedure

*/


BEGIN
   SET NOCOUNT ON
   DECLARE @execstr VARCHAR(255)
   SET @execstr = RTRIM('echo ' + COALESCE(LTRIM(@msg),'-') + CASE WHEN (@overwrite = 1) THEN ' > ' ELSE ' >> ' END + RTRIM(@file))
   EXEC master..xp_cmdshell @execstr
   SET NOCOUNT OFF
END


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.