Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

import flat file into two tables

Posted on 2002-04-09
3
Medium Priority
?
224 Views
Last Modified: 2006-11-17
trying to load a text files into 2 mssql tables. the text file contains rows of record where if it starts with H (header) will go to tab1 & if it starts with numeric will go to tab2.

example of the text file are like this
http://www.geocities.com/alexlow2020/sample.txt

and i have to import into below table
http://www.geocities.com/alexlow2020/table.jpg

the text file have fix char location & i have to extract it out to put into specific col.

anyone have any ideas how to do this or done it b4 ? thanks

0
Comment
Question by:gotreply
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6930551
For ANY kind of import, i do import to a staging table first, which has only varchar field(s). Then, with "simply" SQL, i can validate the data, and move it around to other tables, eventually other staging tables.

You will have to write some long SQL, specifiying all the columns, splitting up the data, but you can be assured that this is the most easy-to-support and flexible solution i found until now.

CHeers
0
 
LVL 1

Accepted Solution

by:
gotaquestion earned 400 total points
ID: 6937352
you should import the file into one staging table like angelll suggested.  and you should add a field to this staging table to be used for a flag as to which table the row is going to eventually insert to.  use the Data Transformation Service and
and in the ActiveX script Transformation properties
determine the flag

'**********************************************************************
'  Visual Basic Transformation Script
'************************************************************************

'  Copy each source column to the destination column
Function Main()
     DTSDestination("flag") = getFlag()
     DTSDestination("f2") = DTSSource("Col002")     DTSDestination("f3") = DTSSource("Col003")
etc..

     Main = DTSTransformStat_OK
     
End Function
Function getflag()

     ''some sort of test
     if isnumeric(DTSSource("headerfield")) then
        getflag = "table1"
        else
        getflag = "table2"
     end if

End Function


after the dts is done you can run an insert into your main table based on the flag field

you could so set up multiple destinations in a DTS object but that is more complicated.
0
 

Author Comment

by:gotreply
ID: 7303807
thks for the help, have solve it after various try, ur comment did give me some idea to furthur my experiment.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
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.
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.

927 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