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

x
?
Solved

EDI - Flat File - SQL

Posted on 2005-03-07
5
Medium Priority
?
316 Views
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","08895288",03/03/2005,0.21,"",0.00,"","","","","",10805
"ORDER_EDI","PO",850,"004010",1,1,"000000001","T","ZZ","008965063T","008965063T","12","95444196EX","95444196EX"
"ORDER_CUSTOMER",1135,"Maltest - Test","","","","","","",""
"ORDER_VENDOR",2556,"test Inter","","","1111 Com Parkway","","LAKE","FL","33825"
"ORDER_SHIPPING","F","","","","","","","","","","","","","","","",0.00
"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","BUYER NAME OR DEPARTMENT: GARBTEST"
"ORDER_NOTE","CONTACT NUMBER [TE]: 867 940-9014 X2286"
"ORDER_NOTE","WAREHOUSE: MALTEST-MT VERNON"
"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"
"ORDER_END",3
0
Comment
Question by:cat4larry
4 Comments
 
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.
0
 

Author Comment

by:cat4larry
ID: 13482306
I want to split it apart into seperate columns
0
 
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.
0
 
LVL 8

Accepted Solution

by:
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
0

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