• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
鱼要的是海洋,鸟要的是天空,我要的是自由!
平凡的人不平凡的人生
博客园    首页    新随笔    联系   管理    订阅  订阅

用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

/*--在文本文件中追加数据

 在文本文件中追加数据
 如果文件不存在,将创建文件

--邹建 2004.08(引用请保留此信息)--*/

/*--调用示例

 exec p_movefile 'c:\aa.txt','测试写入'
--*/
create proc p_movefile
@filename varchar(1000),--要操作的文本文件名
@text varchar(8000) --要写入的内容
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

posted @ 2007-06-29 16:33  伊凡  阅读(429)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3