SQL语句导入导出大全
/******* 导出到excel
exec master..xp_cmdshell ’bcp settledb.dbo.shanghu out c:\temp1.xls -c -q -s"gnetdata/gnetdata" -u"sa" -p""’
/*********** 导入excel
select *
from opendatasource( ’microsoft.jet.oledb.4.0’,
’data source="c:\test.xls";user id=admin;password=;extended properties=excel 5.0’)...xactions
select cast(cast(科目编号 as numeric(10,2)) as nvarchar(255))+’ ’ 转换后的别名
from opendatasource( ’microsoft.jet.oledb.4.0’,
’data source="c:\test.xls";user id=admin;password=;extended properties=excel 5.0’)...xactions
/** 导入文本文件
exec master..xp_cmdshell ’bcp "dbname..tablename" in c:\dt.txt -c -sservername -usa -ppassword’
/** 导出文本文件
exec master..xp_cmdshell ’bcp "dbname..tablename" out c:\dt.txt -c -sservername -usa -ppassword’
或
exec master..xp_cmdshell ’bcp "select * from dbname..tablename" queryout c:\dt.txt -c -sservername -usa -ppassword’
导出到txt文本,用逗号分开
exec master..xp_cmdshell ’bcp "库名..表名" out "d:\tt.txt" -c -t ,-u sa -p password’
bulk insert 库名..表名
from ’c:\test.txt’
with (
fieldterminator = ’;’,
rowterminator = ’\n’
)
--/* dbase iv文件
select * from
openrowset(’microsoft.jet.oledb.4.0’
,’dbase iv;hdr=no;imex=2;database=c:\’,’select * from [客户资料4.dbf]’)
--*/
--/* dbase iii文件
select * from
openrowset(’microsoft.jet.oledb.4.0’
,’dbase iii;hdr=no;imex=2;database=c:\’,’select * from [客户资料3.dbf]’)
--*/
--/* foxpro 数据库
select * from openrowset(’msdasql’,
’driver=microsoft visual foxpro driver;sourcetype=dbf;sourcedb=c:\’,
’select * from [aa.dbf]’)
--*/
/**************导入dbf文件****************/
select * from openrowset(’msdasql’,
’driver=microsoft visual foxpro driver;
sourcedb=e:\vfp98\data;
sourcetype=dbf’,
’select * from customer where country != "usa" order by country’)