-- 프로시저 실행 결과를 txt 파일로 저장하기

-- xp_cmdshell 사용

EXEC sp_configure 'show advanced option', '1'; RECONFIGURE;            

EXEC sp_configure 'xp_cmdshell' , '1'; RECONFIGURE;           

          

DECLARE @SqlQuery varchar(1000) 

SET @SqlQuery = 'echo bcp "EXEC TESTDB.DBO.TEST프로시져" queryout "c:\test.txt" -c -t, -U -P -T  > c:\test.bat'                      

 

-- bcp 실행할배치파일만들기

EXEC master..xp_cmdshell @SqlQuery

 

-- 배치파일실행하기

EXEC master..xp_cmdshell 'c:\TEST.bat'

+ Recent posts