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
/ * - Add data in text files
Additional data in text file If the file does not exist, a file will be created
- Zou Jian 2004.08 (Please keep this information) - * /
/ * - Call example
EXEC P_MOVEFILE 'C: /AA.TXT', 'Test Write' - * / CREATE P_MOVEFILE @ filename varchar (1000), - The text file name @Text varchar (8000) - To write Content asclare @ERR INT, @ src varchar (255), @ Desc varchar (255) Declare @obj Int
Exec @ err = sp_oacreate 'scripting.filesystemObject', @ Obj outif @err <> 0 goto lberr
Exec @ err = sp_oamethod @ obj, 'opentextfile', @ Obj out, @ filename, 8, 1if @err <> 0 goto lberr
Exec @ err = sp_oamethod @ obj, 'writeline', null, @ textif @err <> 0 goto lberr
Exec @ err = sp_oadestroy @objreturn
LBERR: EXEC SP_OAGETERRORINFO 0, @ src out, @DESC OUT SELECT CAST (@err as varbinary (4)) AS error number, @ src AS error source, @ DESC AS error Description Go