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 2005 Forums
 Transact-SQL (2005)
 Import delimeted file

Author  Topic 

GhantaBro
Posting Yak Master

215 Posts

Posted - 2009-06-03 : 16:41:08
Hey Guys,

Need suggestion on how to tackle this or any existing code is even better.... I will have a table that will have the filename and the field delimeter... first row of the file will have the column names... how can I create I create a table with first row as column name and then load the file in that table?

We will have multiple files in the directory at one time; however, the metatable will have the filename and delimeter info.

Thanks for the help guys.

GhantaBro
Posting Yak Master

215 Posts

Posted - 2009-06-04 : 12:14:12
datafile can be as big as 10gb.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-04 : 12:53:29
you can use ssis for this. you require a for each loop to loop through files. then a flat file source and oledb destination to transfer data from file to table.
Go to Top of Page

GhantaBro
Posting Yak Master

215 Posts

Posted - 2009-06-04 : 13:54:54
I have created the script to load the data into temp table and then use the first row from that temp table to create another table using first row as the column names; loading all data again into second table from row2.... I need to know if we can load only few records from datafile into temp table using bulk insert or any other method using script?
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-04 : 14:03:59
yup you can use like:-
SELECT TOP 100 fields... FROM OPENDATASOURCE(...)
Go to Top of Page

SQLRatankalwa
Starting Member

42 Posts

Posted - 2009-06-04 : 14:10:21
Hi

First of all, You need to determine the datatype and format of each column. If you know the number of columns in the file, You have to read the first few recods in the file and understand the data type and format of all the columns based on the data sampling performed on the file, based on the data sampling create the table and then upload the data using bcp, which is the fastest way to upload the data.

I hope this helps

Ratan Kalwa
SQL Server Professionals User Group

http://www.revalsys.com
Go to Top of Page

GhantaBro
Posting Yak Master

215 Posts

Posted - 2009-06-04 : 14:58:00
Thanks guys...it works.
Go to Top of Page
   

- Advertisement -