Solved

Insert txt data into new table

Posted on 2013-05-22
5
242 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 500 total points
ID: 39199531
I'm not 100% positive, but I'm quite sure it does work with the express versions.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In couple weeks ago, I encountered an extremely difficult problem while deploying 2008 SSIS packages to a new environment (SQL Server 2014 standard).  My scenario is: We have one C# application that is calling 2008R2 SSIS packages to load text fi…
My client sends data in an Excel file to me to load them into Staging database. The file contains many sheets that they have same structure. In this article, I would like to share the simple way to load data of multiple sheets by using SSIS.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now