SQL SERVER 와 Excel 의 삽입, 내 보 내기, 가 져 오기

2804 단어 sql
1、 SQL SERVER   Excel  : 
-- ====================================================== 
SELECT * 
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0', 
'Data Source="c:\book1.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...[Sheet1$] 
         ,      Jet   OLE DB        Excel     。 
SELECT * 
FROM OpenDataSource ( 'Microsoft.Jet.OLEDB.4.0', 
  'Data Source="c:\Finance\account.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...xactions 
------------------------------------------------------------------------------------------------- 

2、 Excel     SQL server : 
-- ====================================================== 
SELECT * into newtable 
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0', 
  'Data Source="c:\book1.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...[Sheet1$] 
  : 
SELECT * into newtable 
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0', 
  'Data Source="c:\Finance\account.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...xactions 
------------------------------------------------------------------------------------------------- 

3、 SQL SERVER           Excel   
-- ====================================================== 
T-SQL  : 
EXEC master..xp_cmdshell 'bcp   .dbo.  out c:\Temp.xls -c -q -S"servername" -U"sa" -P""' 
  :S  SQL    ;U   ;P    
  :               
  :EXEC master..xp_cmdshell 'bcp saletesttmp.dbo.CusAccount out c:\temp1.xls -c -q -S"pmserver" -U"sa" -P"sa"' 
EXEC master..xp_cmdshell 'bcp "SELECT au_fname, au_lname FROM pubs..authors ORDER BY au_lname" queryout C:\ authors.xls -c -Sservername -Usa -Ppassword' 
 VB6   ADO  EXCEL    : 
Dim cn  As New ADODB.Connection 
cn.open "Driver={SQL Server};Server=WEBSVR;DataBase=WebMis;UID=sa;WD=123;" 
cn.execute "master..xp_cmdshell 'bcp "SELECT col1, col2 FROM   .dbo.  " queryout E:\DT.xls -c -Sservername -Usa -Ppassword'" 
------------------------------------------------------------------------------------------------ 

4、 SQL SERVER  Excel    : 
-- ====================================================== 
insert into OpenDataSource( 'Microsoft.Jet.OLEDB.4.0', 
'Data Source="c:\Temp.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...table1 (A1,A2,A3) values (1,2,3) 

T-SQL  : 
INSERT INTO  
OPENDATASOURCE('Microsoft.JET.OLEDB.4.0',  
'Extended Properties=Excel 8.0;Data source=C:\training\inventur.xls')...[Filiale1$]  
(bestand, produkt) VALUES (20, 'Test')  
------------------------------------------------------------------------------------------------- 

좋은 웹페이지 즐겨찾기