Monday, April 7, 2014

ექსელის ფაილის წაკითხვა t-sql-ით

ბევრს გაუკეთებია ექსელის Wizard-ით იპორტი Sql-ში, მაგრამ ზოგს Query-ით მოუნდებოდა ამის გაკეთება ზედმეტი ფანჯრების თავის ასარიდებლად, ან თუნდაც თავისი სტილიდან გამომდინარე.

მოკლედ, ეს რომ გააკეთოთ პირველ რიგში დაგჭირდება დრაივერი Access Database Engine

ინსტალაციის შემდეგ ჩართეთ MS SQL Server Management Studio და გაუშვით შემდეგ სკრიპტი:

USE [master]
GO  
sp_configure 'show advanced options', 1
GO 
RECONFIGURE WITH OverRide
GO 
sp_configure 'Ad Hoc Distributed Queries', 1
GO 
RECONFIGURE WITH OverRide
GO 
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1
GO  
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1
GO 
EXEC sp_configure 'show advanced options', 1
GO 
RECONFIGURE 
GO 
EXEC sp_configure 'xp_cmdshell', 1
GO 
RECONFIGURE 
GO 


SELECT * FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=C:\Users\lasha.morgoshia\Desktop\temp\Book1.xlsx;HDR=YES;IMEX=1','SELECT * FROM [Sheet1$]')

No comments:

Post a Comment