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
--创建存储过程
ALTER procedure [dbo].[sp_WriteFileMy]
@msg nvarchar(300)
as
begin
DECLARE @cmd sysname,@var nvarchar(400),@Append int=1,@file1 varchar(20),@file2 varchar(20)
--/*
--,是否追加到现有文件。,创建新的文件,,追加到现有文件。
set @var = CONVERT(varchar(100), GETDATE(), 120) + ‘ : ‘ + @msg
set @file1 =‘d:\VarOut.txt‘
set @file2 =‘d:\VarOut2.txt‘
if @Append=0
begin--创建新的文件。
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