Showing posts with label Excel. Show all posts
Showing posts with label Excel. Show all posts

Wednesday, July 8, 2009

How to use Excel with SQL Server linked servers and distributed queries

การทำ Link Server ไปยัง Excel

More Information http://support.microsoft.com/kb/306397/

Use SQL OPENROWSET OPENDATASOURCE Query Excel

เราสามารถใช้คำสั่ง OPENROWSET OPENDATASOURCE สำหรับ Query ไฟล์ Excel ได้ตามตัวอย่างข้างล่างนี้

ก่อนอื่นถ้ายังไม่เปิดการใช้งาน OPENROWSET OPENDATASOURCE ใน SQL Server 2005 ให้เปิดการใช้งานก่อน ดูวิธีได้ตาม Link นี้
http://usedotnet.blogspot.com/2009/07/sql-server-blocked-access-to-statement.html

ตัวอย่างเป็นการ Query จากไฟล์ C:\Customers.xls ที่ Sheet ชื่อ Customers

SELECT * FROM OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0',
'Data Source=C:\Customers.xls;Extended Properties=Excel 8.0')...[Customers$]

SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\Customers.xls', [Customers$])

SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\Customers.xls', 'SELECT * FROM [Customers$]')

SELECT * FROM OPENROWSET('MSDASQL',
'Driver={Microsoft Excel Driver (*.xls)};DBQ=C:\Customers.xls',
'SELECT * FROM [Customers$]')

More Information: http://support.microsoft.com/kb/321686