How to create dynamic table based on csv file?

I am trying to create a package to load latest csv file into the sql server and every time it should create a new table based on csv file.
1) First past of recognizing latest csv file is done, using script task. (thanks you guys for awesome post)
2) To create a table based on the latest csv. I have no clue on this one. Currently, I am using data flow task.
a)Flat File Source- using variable base on script task the file name is recognized from the source folder.
b) OLE DB Destination - how can i create table dynamically?
Also datatype for fields should be nvarchar(max)
more ▼

asked Aug 13 '12 at 07:04 PM in Default

hope gravatar image

50 4 4 5

(comments are locked)
10|1200 characters needed characters left

2 answers: sort voted first

Hey thanks for the suggestion. I applied a different approach to that.

1) I used a script task to identify the latest csv file and put that file name into a variable based on code provided on the following link:


2) I used a second script task to to create a table for every csv file based on code provided on the following link:


Now I need to call the variable using connection string to get the latest csv file. how can I call that variable?
more ▼

answered Aug 16 '12 at 03:17 PM

hope gravatar image

50 4 4 5

Hey, I found a solution to it. Using a file management tool which keeps only one file at a time in a folder and using the code on the second link I can create a table.
Aug 16 '12 at 08:00 PM hope
(comments are locked)
10|1200 characters needed characters left

can you not try something like:

INTO tempdb..temptable
'SELECT * FROM test.csv')  
more ▼

answered Aug 14 '12 at 05:19 PM

swirl80 gravatar image

60 1

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: Aug 13 '12 at 07:04 PM

Seen: 3513 times

Last Updated: Aug 17 '12 at 07:40 AM