Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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
LVL 70

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

580 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