Well, it's not incredibly easy, or I'd let you have it. ;-) The short answer is you have to do it in the other order: handle the address part first, and the customer part second.

Your flat file db repeats address information and is thus denormalized. It sounds like you've normalized the data model in SQL Server, so in addition to loading the data into the database, you need to normalize it. In this case that means generate only one row for each unique address. You can use Perl to simplify the work a little bit depending on the amount of data you're processing.

Basically, when you read a row, separate the address information and look that up in the address table first. If you get a row, remember the key value, and use that when you insert the customer data. (The Perl simplification in the case of a small data set would be to save the database key value in a hash so you don't have to keep querying.) If you don't find the address, insert it, and retrieve the new key (again storing it in the Perl hash if practical). Then proceed to handling the customer data as in the previous case.

HTH


In reply to Re: Perl ODBC question by VSarkiss
in thread Perl ODBC question by kendo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.