Stored procedures, capturing error messages to log files

Source: Internet
Author: User

Use [ERPDB1]
GO
/****** object:storedprocedure [dbo].    [Sp_writefilemy] Script date:12/26/2014 15:00:46 ******/
SET ANSI_NULLS on
GO
SET QUOTED_IDENTIFIER ON
GO
--Create a stored procedure
ALTER procedure [dbo]. [Sp_writefilemy]
@msg nvarchar (300)
As
Begin


DECLARE @cmd sysname, @var nvarchar, @Append int=1, @file1 varchar, @file2 varchar (20)
--/*
--, whether to append to an existing file. , create a new file, and append to the existing file.
Set @var = CONVERT (varchar (+), GETDATE (), +) + ': ' + @msg
Set @file1 = ' D:\VarOut.txt '
Set @file2 = ' D:\VarOut2.txt '

If @Append =0
begin--Create a new file.
SET @cmd = ' echo ' + @var + ' > ' + @file1
End
Else
Begin
SET @cmd = ' echo ' + @var + ' > ' + @file2
EXEC master. xp_cmdshell @cmd

Set @cmd = ' Copy '[email protected]+ ' + '[email protected]+ '[email protected]+ '/b '
EXEC master. xp_cmdshell @cmd
Set @cmd = ' del '[email protected]
EXEC master. xp_cmdshell @cmd
End
--*/
End

Stored procedures, capturing error messages to log files

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.