用SQL在文字檔案中追加資料

2021-04-14 11:32:32 字數 1089 閱讀 8259

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/*--在文字檔案中追加資料

在文字檔案中追加資料

如果檔案不存在,將建立檔案

--鄒建 2004.08(引用請保留此資訊)--*/

/*--呼叫示例

exec p_movefile 'c:/aa.txt','測試寫入'

--*/

create proc p_movefile

@filename varchar(1000),--要操作的文字檔案名

@text varchar(8000) --要寫入的內容

asdeclare @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 錯誤描述

用SQL在文字檔案中追加資料

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 在文字檔案中...

用SQL在文字檔案中追加資料

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 在文字檔案中...

用SQL在文字檔案中追加資料

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 在文字檔案中...