/**
* 授权
*/
EXEC sp_configure 'show advanced options',1;
go
reconfigure;
go
exec sp_configure 'xp_cmdshell',1;
go
reconfigure;
go
/**导入指定表的文本文件*/
EXEC master..xp_cmdshell 'bcp dbname..tablename in d:\DT.txt -c -Sservername -Usa -Ppassword'
exec master..xp_cmdshell 'bcp "select * from dbname..tablename" queryout "D:\20140528.xls"-c -Sservername -Uuser -Ppassword'
xp_cmdshell参数说明
下面是我自己写的一个存储过程,可以直接拿去使用
第一步,先要授权。上面有授权的SQL代码
if exists(select * from sysobjects where type='p' and name='sp_export_posm_data') begin
drop procedure sp_export_posm_data;