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
 SQL Server 2008 Forums
 SSIS and Import/Export (2008)
 import CSV file into Table

Author  Topic 

albertkohl
Aged Yak Warrior

740 Posts

Posted - 2011-04-06 : 15:14:42
okay, very basic question, but with a fun curve ball.

how can i import a .csv file into a NEW MSSQL Table. now here's the trick. the table and csv files cannot be a set format. so i need SSIS or something else inbetween to dynamically create a table, based off the header of the file. make sense? kinda like if i manually imported a table with ssis.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-04-06 : 15:23:44
Use OPENQUERY/SELECT * INTO.

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

Subscribe to my blog
Go to Top of Page

albertkohl
Aged Yak Warrior

740 Posts

Posted - 2011-04-06 : 15:29:54
Tara, can you give me an example? only thing i've ever used was openrowset on a csv or xls file, and since we moved to x64, it doesnt work because of the Jet Driver Support :(

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-04-06 : 15:35:33
Just search for OPENQUERY and you'll see many, many examples. You can either search the forums or google it.

I don't have any information about the Jet driver regarding x64.

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

Subscribe to my blog
Go to Top of Page

albertkohl
Aged Yak Warrior

740 Posts

Posted - 2011-04-06 : 15:42:56
i guess my issues is i have to link to the flat file in order to use openquery against it right? that's where my issue would be here...
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-04-06 : 15:43:41
I don't see why that's a problem, that's what OPENQUERY does.

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

Subscribe to my blog
Go to Top of Page

albertkohl
Aged Yak Warrior

740 Posts

Posted - 2011-04-06 : 16:04:14
maybe i'm confused, do i have to create a linked server to the text file first, and then access the data using openquery?

do i just access the data directly w/ openquery w/o linking to it first?

maybe that'll help me figure out how to do this... everything i find is basicall:

select * from openquery(mylinkedobject,select * from mytable)

my issue is the portion where i link to the file. i cant figure that out.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-04-06 : 16:24:09
Oh I didn't realize you'd have a problem with a linked server. Try OPENROWSET: http://msdn.microsoft.com/en-us/library/ms190312.aspx

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

Subscribe to my blog
Go to Top of Page

albertkohl
Aged Yak Warrior

740 Posts

Posted - 2011-04-06 : 16:46:55
tried:


select * INTO EMP_TABLE from OpenRowset('MSDASQL',
'Driver={Microsoft Text Driver (*.txt; *.csv)};
DefaultDir=C:\Temp;
Extended properties=''ColNameHeader=True;Format=CSVDelimited;''','select * from junk.txt')


got:
OLE DB provider "MSDASQL" for linked server "(null)" returned message "[Microsoft][ODBC Driver Manager] Invalid connection string attribute".
OLE DB provider "MSDASQL" for linked server "(null)" returned message "[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "(null)".


any ideas? i checked my Linked Server > Providers list and i see MSDASQL in there, so that means the driver exists right?


Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-04-06 : 16:54:01
Try C:\Temp\ instead of C:\Temp and ensure that it is a valid path and file on the database server and not your client machine.

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

Subscribe to my blog
Go to Top of Page

albertkohl
Aged Yak Warrior

740 Posts

Posted - 2011-04-06 : 17:05:20
tried it, and i running this local to the server, so check, and check, same error :(
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-04-06 : 17:49:19
I'll defer to other SQLTeam members as this isn't my area of expertise.

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

Subscribe to my blog
Go to Top of Page
   

- Advertisement -