Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Insert txt data into new table

Posted on 2013-05-22
5
Medium Priority
?
266 Views
Last Modified: 2016-02-11
Hello everyone,

I have a rather large .txt (50mb) that I need to insert into a table in SQL Server... There are at least 300 columns in this .txt, so I really didn't want to create this table manully, but to use something like
insert * into myTable from *****

Open in new window


I tried this code:
select * from openrowset('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)};DefaultDir=M:\Area\POSICON\;','select * from p2m0001_posicon_vcat003cto_GeradaProd_21052013_235311_Copy_21052013_235318.txt');

Open in new window


But it returned my this error:
OLE DB provider "MSDASQL" for linked server "(null)" returned message "[Microsoft][ODBC Text Driver] '(unknown)' is not a valid path.  Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.".
Msg 7303, Level 16, State 1, Line 6
Cannot initialize the data source object of OLE DB provider "MSDASQL" for linked server "(null)".

Open in new window


Any ideas??
0
Comment
Question by:toddinho
  • 3
  • 2
5 Comments
 
LVL 23

Expert Comment

by:nemws1
ID: 39189172
Have you used the Import tool in SSMS?

1) Right Click the database in the Object Explorer in SSMS
2) Select "Tasks"
3) Select "Import Data..."
4) Click Next
5) Under "Data Source" select "Flat File Source"
6) Browse to your file  (by "File Name")
7) Play with the setting and get them to however your TXT file is formatting
8) Click "Next" to see a preview (your field delimiter is set here as well)
9) Click "Next" through the rest of the screens - I tend to not need to touch these
10) Magic occurs (actually SSMS creates your table and loads the text file into it)
11) Profit! :)
0
 

Author Comment

by:toddinho
ID: 39189221
The problem is that it needs to be automatic, via Stored Procedure... I managed to open it (though it came wrongly, because it needs to be treated first), pasting it into local machine directory... When I use some mapped network drive, it cant find the file...

One other thing: is it possible to treat the file before selecting? For example, this .txt has a header with current date, and then just in second line has the columns... So when I select directly I get columns F1,F2,... and the data comes all mixed up...
0
 
LVL 23

Expert Comment

by:nemws1
ID: 39189289
You'll have to create a project in SSIS if you need to import a bunch of these (and skip the first line/etc.)
0
 

Author Comment

by:toddinho
ID: 39199447
Is SSIS compatible with SQL Server 2008 R2 Express??
0
 
LVL 23

Accepted Solution

by:
nemws1 earned 1500 total points
ID: 39199531
I'm not 100% positive, but I'm quite sure it does work with the express versions.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A couple of weeks ago, my client requested me to implement a SSIS package that allows them to download their files from a FTP server and archives them. Microsoft SSIS is the powerful tool which allows us to proceed multiple files at same time even w…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question