SQL Server: Read,Write data from Excel/CSV/Text file using T-SQL

Categories: Database; Tagged with: ; @ September 13th, 2012 18:28

-- Select Data from Excel file
    SELECT *
    FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
    'Excel 8.0;Database=C:\DavidTemp\channel.xls', [Sheet1$])

-- Select data from CVS file:
    SELECT * FROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0',
    'Text;Database=C:\DavidTemp\;','SELECT * FROM [channel.csv]')

 

-- Select data From text file:
    SELECT * FROM OPENROWSET ( 'Microsoft.Jet.OLEDB.4.0',  
    'TEXT;Database=C:\DavidTemp\','SELECT * from channel_noData.txt')

 

REF:

Ad Hoc Querying

 

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.