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
 Import data from csv into SQL Server

Author  Topic 

lanti_p
Starting Member

15 Posts

Posted - 2012-01-10 : 03:57:27
Hello everybody,


I am facing an issue while trying to import data (1.2 mio records) into SQL Server 2008.
The problem is that I have all the content in one CSV, and in another one, I have all field headers.
I do not have the field headers in the main CSV, so I need to upload them both.
Any idea how can I achieve this?


Thank you all and regards,
lantip

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-10 : 04:22:07
you mean you need to store field headers also as values inside table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

lanti_p
Starting Member

15 Posts

Posted - 2012-01-10 : 04:35:48
Yes, of course I tried that ... but I am getting error with headers assigned to wrong columns (fields) .. despite the fact that excel need half an hour to perform that ... :)



quote:
Originally posted by visakh16

you mean you need to store field headers also as values inside table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-10 : 04:59:04
hmm...thats was a question..do you need to store field headers also as values inside table?



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

lanti_p
Starting Member

15 Posts

Posted - 2012-01-10 : 05:07:33
oooops sorry ...

I do not want to storee filed headers as values inside the table.
I just want to assign those field headers as table header columns.
The problem is that values and field headers are kept in different sheets.



quote:
Originally posted by visakh16

hmm...thats was a question..do you need to store field headers also as values inside table?



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-10 : 05:08:27
thats means the table has to be created dynamically isnt it?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

lanti_p
Starting Member

15 Posts

Posted - 2012-01-10 : 05:29:21
Logically yes, because I am not able to create a table with columns named as per another sheet, and data from another ...

quote:
Originally posted by visakh16

thats means the table has to be created dynamically isnt it?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-10 : 06:50:03
you can do it like this


SELECT * INTO YourTableName FROM OPENROWSET('MSDASQL',

'Driver={Microsoft Text Driver (*.txt; *.csv)};

DefaultDir=your csv path here;',

'SELECT * FROM filename.csv')





------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -