如何用SQL語句查詢Excel資料?

2022-04-05 20:14:24 字數 1385 閱讀 5709

q:如何用sql語句查詢excel資料?

a:下列語句可在sql server中查詢excel工作表中的資料。

excel 2007和2010版本:

select * from opendatasource( 'microsoft.ace.oledb.12.0', 'data source="c:\book1.xlsx";user id=admin;

password=;extended properties=excel 12.0')...[sheet1$]

select * from openrowset('microsoft.ace.oledb.12.0','excel 12.0;database=c:\book1.xlsx', 'select * from [sheet1$a1:d100]')

select * from openrowset('microsoft.ace.oledb.12.0','excel 12.0;database=c:\book1.xlsx', 'select * from [sheet1$]')

excel 2003版本:

select * from opendatasource( 'microsoft.jet.oledb.4.0','data source="c:\book1.xls";user id=admin;

password=;extended properties=excel 8.0')...[sheet1$]

select * from openrowset('microsoft.jet.oledb.4.0','excel 8.0;database=c:\book1.xls', 'select * from [sheet1$]')

select * from openrowset('microsoft.jet.oledb.4.0','excel 8.0;database=c:\book1.xls', 'select * from [sheet1$a1:d100]')

/*而且,還需要用擁有伺服器sysadmin角色許可權的登入帳號,先執行下列語句開啟sql server的'ad hoc distributed queries'開關。*/

exec sp_configure 'show advanced options',1;reconfigure;

exec sp_configure 'ad hoc distributed queries',1;reconfigure;

/*執行查詢後,再用相反順序的語句,關閉'ad hoc distributed queries'開關。*/

exec sp_configure 'ad hoc distributed queries',0;reconfigure;

exec sp_configure 'show advanced options',0;reconfigure;

如何用SQL語句查詢Excel資料?

如何用sql語句查詢excel資料?q 如何用sql語句查詢excel資料?a 下列語句可在sql server中查詢excel工作表中的資料。2007和2010版本 select from opendatasource microsoft.ace.oledb.12.0 data source c ...

如何用SQL語句進行模糊查詢?

like條件一般用在指定搜尋某字段的時候,通過 萬用字元的作用實現模糊查詢功能,萬用字元可以在前面也可以在後面或前後都有。搜尋以mian開頭 select from teble where title like mian 搜尋以mian結束 select from teble where title...

MSSQL中如何用SQL語句查詢字段型別

最佳答案 這個肯定得從系統表中查詢了。select a.name as column b.name as typefrom syscolumns a,systypes bwhere a.id object id 表名 and a.xtype b.xtype把 表名 替換成你要檢視字段型別的表名,比如...