If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Insert records into unusual table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-21-03, 13:16
rsteele rsteele is offline
Registered User
 
Join Date: Dec 2002
Posts: 7
Insert records into unusual table

This problem goes against everything that I've been taught and have always read about, so please don't think I designed this.

I'm trying to write a procedure to insert orders from 3 tables into one table to import into our mail order system. That's not a problem.
The problem is the mapping.
The basic design:

tblOrders (order_id, customer_id, shipto_id, billto_id, card_num, etc.)
tblOrderItems ( item_id, item_price, item_name, etc.)
tblContacts(contact_id, f_name, l_name, card_no, etc.)

BUT, I have to export to this table format.....REALLY!!

tblOrdersToExport (
order_id, contact_id, fname, lname, address, city, state, zip, country,
---- now here's the good part
product1, quanity1, price1,
product2, quanity2, price2,
product3, quanity3, price3,
product4, quanity4, price4,
product5, quanity5, price5,
order_continued
)

The order_continued is flagged if the order contains more line items than product fields (5), and the row doesn't contain any information except product#, quanity#, price# and the order_continued flag.

I think I've got the right idea. I'm playing with cursors and some procedures, but I'm running into problems when I have more than 5 items and have to insert into this very unusual structure.

I know this is strange, but it's what I have to work with and i have no way of changing the db structure or table layout since it's part of a program that was purchased and there's not way that I can recode anything.

If someone can make sense of what I'm trying to do, I can post an example if it will help. I wanted to keep the length of this message short and it's very hard to explain sense it doesn't make much sense.

thanks
Randy
Reply With Quote
  #2 (permalink)  
Old 02-21-03, 17:38
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: Insert records into unusual table

Can you post the code you've written so far, and indicate where it runs into problems? It sounds like you just need to loop through the items and whenever you get to a multiple of 5 + 1 start a new record - i.e. at item 6, 11, 16, ...

Whoever designed their database should be shot!
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On