if exists (select * from dbo.sysobjects where id = object_id(n'[dbo].[p_movefile]') and objectproperty(id, n'isprocedure') = 1)
drop procedure [dbo].[p_movefile]
go
/*--在文本文件中追加數(shù)據(jù)
 在文本文件中追加數(shù)據(jù)
 如果文件不存在,將創(chuàng)建文件
--鄒建 2004.08(引用請保留此信息)--*/
/*--調(diào)用示例
 exec p_movefile 'c:/aa.txt','測試寫入'
--*/
create proc p_movefile
@filename varchar(1000),--要操作的文本文件名
@text varchar(8000) --要寫入的內(nèi)容
as
declare @err int,@src varchar(255),@desc varchar(255)
declare @obj int
exec @err=sp_oacreate 'scripting.filesystemobject',@obj out
if @err<>0 goto lberr
exec @err=sp_oamethod @obj,'opentextfile',@obj out,@filename,8,1
if @err<>0 goto lberr
exec @err=sp_oamethod @obj,'writeline',null,@text
if @err<>0 goto lberr
exec @err=sp_oadestroy @obj
return
lberr:
 exec sp_oageterrorinfo 0,@src out,@desc out
 select cast(@err as varbinary(4)) as 錯誤號
  ,@src as 錯誤源,@desc as 錯誤描述
go