Connecting Tech Pros Worldwide Forums | Help | Site Map

Looking for suggestions on how to do something

Bishop
Guest
 
Posts: n/a
#1: Dec 8 '06
I have text files that I download daily from one of our vendors. They are
in this format (and they won't change the way they do it)

File1:
ProductID, Description, Price, etc....

File2:
ProductID, QTY

Outside of loading them into a table in the DB and joining the data, does
anyone have any ideas on how to merge the two files so they look like this:

ProductID, Description, Price, QTY

The only thing I can think of is to store the ProductID and QTY in an array
or collection and loop through it for each entry.

Any suggestions appreciated.



Spam Catcher
Guest
 
Posts: n/a
#2: Dec 8 '06

re: Looking for suggestions on how to do something


"Bishop" <nospam@nospam.comwrote in
news:#QCUwswGHHA.4652@TK2MSFTNGP04.phx.gbl:
Quote:
Outside of loading them into a table in the DB and joining the data,
does anyone have any ideas on how to merge the two files so they look
like this:
>
ProductID, Description, Price, QTY
>
The only thing I can think of is to store the ProductID and QTY in an
array or collection and loop through it for each entry.
How about opening 2 file readers, one for each file.

Read each line and concatenate them together - then output to a file
writer?
Bishop
Guest
 
Posts: n/a
#3: Dec 8 '06

re: Looking for suggestions on how to do something


That's a great idea. I'll just add some validation to make sure the item
numbers match before I concatenate them.

Thanks!


"Spam Catcher" <spamhoneypot@rogers.comwrote in message
news:Xns9893AE3A25E24usenethoneypotrogers@127.0.0. 1...
Quote:
"Bishop" <nospam@nospam.comwrote in
news:#QCUwswGHHA.4652@TK2MSFTNGP04.phx.gbl:
>
Quote:
>Outside of loading them into a table in the DB and joining the data,
>does anyone have any ideas on how to merge the two files so they look
>like this:
>>
>ProductID, Description, Price, QTY
>>
>The only thing I can think of is to store the ProductID and QTY in an
>array or collection and loop through it for each entry.
>
How about opening 2 file readers, one for each file.
>
Read each line and concatenate them together - then output to a file
writer?

Terry
Guest
 
Posts: n/a
#4: Dec 8 '06

re: Looking for suggestions on how to do something


Reminds me of the old days of doing file updates on tape, Master file (on
tape) in, transaction file (on tape or cards etc) in, new master file out.
Need to compare Prooduct key for hi, low or equal. Mater file product id >
transaction file key implies missing product id for trans. If master file
product id <, advance till >=. When equal, update.
--
Terry


"Bishop" wrote:
Quote:
I have text files that I download daily from one of our vendors. They are
in this format (and they won't change the way they do it)
>
File1:
ProductID, Description, Price, etc....
>
File2:
ProductID, QTY
>
Outside of loading them into a table in the DB and joining the data, does
anyone have any ideas on how to merge the two files so they look like this:
>
ProductID, Description, Price, QTY
>
The only thing I can think of is to store the ProductID and QTY in an array
or collection and loop through it for each entry.
>
Any suggestions appreciated.
>
>
>
Martin Milan
Guest
 
Posts: n/a
#5: Dec 9 '06

re: Looking for suggestions on how to do something


"Bishop" <nospam@nospam.comwrote in
news:#QCUwswGHHA.4652@TK2MSFTNGP04.phx.gbl:
Quote:
I have text files that I download daily from one of our vendors. They
are in this format (and they won't change the way they do it)
>
File1:
ProductID, Description, Price, etc....
>
File2:
ProductID, QTY
>
Outside of loading them into a table in the DB and joining the data,
does anyone have any ideas on how to merge the two files so they look
like this:
>
ProductID, Description, Price, QTY
>
The only thing I can think of is to store the ProductID and QTY in an
array or collection and loop through it for each entry.
>
Any suggestions appreciated.
>
>
Create a class to store a Description, Price and Qty. Call this Class
"ProdInfo" Start reading file 1, and populate a hash array with ProdInfo
objects, keyed by ProductID. That means you'll be filling in the
description and price.

Now read file 2, doing much the same thing, using the key to get at the
ProductID and then either work with an existing object in the hash, or
create a new object.

Once you've finished reading file 2, you should then be able simply
right the results you are looking for simply by enumerating the hash.


Personally though, I'd be going down the Database route. This is a five
minute job with SQL server...

Martin

Closed Thread