EDI - Flat File - SQL

Posted on 2005-03-07
Medium Priority
Last Modified: 2008-03-06
I have a flat file that gets converted from an EDI file.  What is the best way to get this file imported into a SQL database?  

The top part is the header information and the bottom are the line items.   Thanks

"ORDER_CUSTOMER",1135,"Maltest - Test","","","","","","",""
"ORDER_VENDOR",2556,"test Inter","","","1111 Com Parkway","","LAKE","FL","33825"
"ORDER_ADDRESS","BT","Bill To","0089650630000","9","DUNS+4","MALTEST","","","P.O. BOX 4056","","DANVILLE","IL","64334"
"ORDER_ADDRESS","ST","Ship To","008965063W008","9","DUNS+4","MALTEST VERNON","","","78 LAKE TER N E","","MT. VERNON","IL","65464"
"ORDER_TERMS","ITD","02","End of Month (EOM)",60,,0.00,0,,"3","Invoice Date","","",,0.00,0.00,0.00,0.00,0.00," NET 60 ROG"
"ORDER_DATE_TIME","DTM",03/04/2005,,"002","Delivery Requested","",""
"ORDER_NOTE","CONTACT NUMBER [TE]: 867 940-9014 X2286"
"ORDER_NOTE","CONTACT NUMBER [TE]: (618) 244-9100"
"ORDER_REF_NUM","089528","VN","Vendor Order Number",""
"ITEM",0,"002","708862001202","UP","UPC Consumer Package Code (1-5-5-1)",1.0000,"CA",360.00,"","","","",""
"ITEM_DETAILS",0.00,0.00,0.00,0,0.00,"",0,"LENSES +150"
"ITEM_ID","708862001202","UP","UPC Consumer Package Code (1-5-5-1)"
"ITEM_ID","814112","IN","Buyer Item Number"
"ITEM",1,"003","708862001042","UP","UPC Consumer Package Code (1-5-5-1)",1.0000,"CA",360.00,"","","","",""
"ITEM_DETAILS",0.00,0.00,0.00,0,0.00,"",0,"LENSES +200"
"ITEM_ID","708862001042","UP","UPC Consumer Package Code (1-5-5-1)"
"ITEM_ID","814113","IN","Buyer Item Number"
"ITEM",2,"004","708862001233","UP","UPC Consumer Package Code (1-5-5-1)",1.0000,"CA",360.00,"","","","",""
"ITEM_DETAILS",0.00,0.00,0.00,0,0.00,"",0," LENSES +250"
"ITEM_ID","708862001233","UP","UPC Consumer Package Code (1-5-5-1)"
"ITEM_ID","814114","IN","Buyer Item Number"
Question by:cat4larry
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 69

Expert Comment

by:Scott Pletcher
ID: 13481429
If you just want to load it into a VARCHAR() column, BULK INSERT command should be the fastest way.

Author Comment

ID: 13482306
I want to split it apart into seperate columns
LVL 75

Expert Comment

by:Anthony Perkins
ID: 13483415
>>I want to split it apart into seperate columns<<
Since there is a varying number of columns, you can place it in a temporary table with a varchar column first as Scott has suggested.  You may be able to do is a table with two columns, the first to indicate the type of record, the second the rest.  Once it is in this temporary table you can pull the relevant parts out into the final tables by parsing the delimitted fields.

The other approach you can do is import all the rows into a temporary table with 20 columns, and then query the individual record types into the final table.  Not sure if you can do this with BULK INSERT as there will be rows with missing fields, but I suspect you can, otherwise you certainly can import it in with DTS.

Accepted Solution

Julianva earned 1000 total points
ID: 13484613
The easiest way to import a text file to SQL is with DTS -
you can map the file columns to the database columns and import

 Create a DTS package

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

764 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