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