Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How do I open a .csv file in sql?

Author  Topic 

larryg003
Starting Member

18 Posts

Posted - 2010-08-05 : 19:34:06
Hi guys,

I want to upload a .csv file (it was made in excel) into sql and then use the file to match some values from a larger database which is on a server.

I tried opening the file in sql using the file->open->file, but all i got was a .txt file with a bunch of gibberish.

Any ideas?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-08-05 : 20:09:20
If it's truly a csv file, then you can import the data via the import/export wizard in SSMS. You can also use bcp.exe, but you'd need to create the table first.

If you tried opening the file in SSMS and got gibberish, then it doesn't sound like a real csv file.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

kashyap_sql
Posting Yak Master

174 Posts

Posted - 2010-08-06 : 01:19:20
try this

SELECT * INTO Table_name
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=d:\table_name.xls', 'SELECT * FROM [Sheet1$]')




With Regards
Kashyap M
Go to Top of Page
   

- Advertisement -