bcp 可以实现数据的导入导出。
EXEC master..xp_cmdshell 'bcp test.dbo.P_Aspect in c:\temp1.txt -c -q -S"servername" -U"sa" -P""'
//导入 EXEC master..xp_cmdshell 'bcp test.dbo.P_Aspect out c:\temp1.txt -c -q -S"servername" -U"sa" -P""'
//导出
EXEC master..xp_cmdshell 'bcp test.dbo.P_Aspect in c:\temp1.txt -c -q -S"servername" -U"sa" -P""'
//导入 EXEC master..xp_cmdshell 'bcp test.dbo.P_Aspect out c:\temp1.txt -c -q -S"servername" -U"sa" -P""'
//导出
然后将你的查询结果存入表1
执行DTS
@bcpCommand varchar(2000)SET @FileName = REPLACE('c:\authors_'+CONVERT(char(8),GETDATE(),1)+'.txt','/','-')SET @bcpCommand = 'bcp "SELECT * FROM pubs..authors ORDER BY au_lname" queryout "'
SET @bcpCommand = @bcpCommand + @FileName + '" -U garth -P pw -c'EXEC master..xp_cmdshell @bcpCommand