Results 1 to 6 of 6

Thread: Cleaning up data for import to database

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    3

    Cleaning up data for import to database

    Hello all, I am new here so I hope i do this in the correct forum.

    I have an excel user who each week receives an EDI transfer of orders from one, two or three different companies. Each EDI may have one, two or all three depending. THere are only three companies ever.

    The problem that I have is that the data is formatted so crazily that I need some major clean up module before I can import it into a database to work with the data. I am not even sure VB can do it. I have attached an example of the raw data and an example of the ideal data. The data always appears like this so one instance would work ongoing.

    Essentially what I need to do is eliminate the crap rows of junk data and assign the company name and the "for" date to each part ordered so that the data would look like this

    Company Name Date Needed Model Part
    Company 1 7/10/2006 blah blah
    Company 2 7/10/2006 blah blah
    Company 3 7/10/2006 blah blah
    Company 3 7/10/2006 blah blah

    What you will see in the attachment is that the company name and date needed are listed in columns above all of the data that corresponds. Below the company in the same column can be either a number or the word "for" or "line" for some reason. I need to somehow take the company name and move it left and fill it down for the corresponding data (sheet two of the attachment shows how it would ideally look.)

    If anyone can give me some direction with this I would be most appreciative or if you could direct me to something to read on this. ANYTHING closer would be greatly appreciated as well. ... Thank you in advance.
    Attached Files Attached Files

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Cleaning up data for import to database

    This is a simple Tab Delimited file. You can easily read through the file using the following code

    VB Code:
    1. Dim lngFile1 As Long
    2.     Dim strBuffer As String
    3.     Dim strFields() As String
    4.    
    5.     Dim strDate As String
    6.    
    7.     lngFile1 = FreeFile
    8.     Open "c:\uncorrected.txt" For Input As lngFile1
    9.    
    10.     Do
    11.         Line Input #lngFile1, strBuffer
    12.         strFields = Split(strBuffer, vbTab)
    13.         Select Case strFields(0)
    14.             Case "LINE"
    15.                 If StrComp(strFields(1), "Chassis", vbTextCompare) <> 0 Then
    16.                     'the strFields array now contains the information for Line, Chassis, Part etc..
    17.                     'otherwise it contains the header info so ignore the line
    18.                 End If
    19.             Case "For"
    20.                 'contains the date
    21.                 strDate = strFields(2)
    22.             Case "FOR"
    23.                 'the strfields array is populated with the FOR information
    24.             Case Chr$(12) 'Page line, the next line contains the Company Name
    25.                 Line Input #lngFile1, strBuffer
    26.                 strFields = Split(strBuffer, vbTab)
    27.             Case Else
    28.                 If Left$(strFields, 3) = "F23" Then 'may need to change F23 to handle more types
    29.                 Else
    30.                    'Unknown line - raise an error or ignore
    31.                 End If
    32.         End Select
    33.            
    34.     Loop Until EOF(lngFile1)
    35.    
    36.     Close lngFile1

    For each Select Case you would create an output line and then print it to the corrected.txt file when ready.

    As long as the File Layout stays consistent this code will work.

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Cleaning up data for import to database

    Have you considered opening it in Excel? Getting closer to the source of the creation would be ideal, since you'd have a better chance of dealing with it. If you open it in Excel and it appears... well, then you can use an Excel object to loop through it, and create your corrected text file.

  4. #4

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    3

    Re: Cleaning up data for import to database

    Thank you both! I feel like we are getting somewhere. Yes I open the file in excel but you cant post excel files as attachments on this site. How would the module differ from the txt file module above? I want to go the most effective route.

    Thanks again!

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Cleaning up data for import to database

    But that is not an EDI transmission - that appears to be a report/list file from a mainframe type of machine.

    You need to get rid of the headings - brucevde is showing you the logic to process, in a loop, and ignore meaningless lines...

    Can you get that data without the headings?

    If not I would develop a silly-little filter program to process the input file and give clean output from that. Then a bulk insert can be done from that clean file.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    3

    Re: Cleaning up data for import to database

    thanks! it is an edi report that is output into a text file. i can actually jsut disregard the headings. its not great for normalizaiton of data but it wont stop the process. Thank you very much!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width