On Mar 19, 9:11 pm, BigMac <[email protected]> wrote:
> Hello.  I'm trying to create an append query that would handle the
> following table structure... I'm looking to take records that look
> like:
>
> (Record1)
> InvoiceID (KEY)
> PayoutType1
> PayoutAmount1
> PayoutType2
> PayoutAmount2
> PayoutType3
> PayoutAmount3
> (END Record1)
>
> Where each record has multiple payment types for a single invoice.
> Instead, I'd like to have another table that handles just payment
> types/amounts and where it could have many records (multiple payment
> types/amounts) for a single invoice instead of trying to create an
> indexing field based on a finite set of payments)
>
> Instead, I would like this:
>
> (Record1)
> PaymentId (KEY)
> InvoiceID
> PayoutType
> PayoutAmount
> (END Record1)
>
> (Record2)
> PaymentId (KEY)
> InvoiceID
> PayoutType
> PayoutAmount
> (END Record2)
>
> (Record3)
> PaymentId (KEY)
> InvoiceID
> PayoutType
> PayoutAmount
> (END Record3)
>
> I may be in the wrong group.  I spent 60 minutes trying to find the
> right group and if I didn't find it, I assure you I don't mean to
> intrude... but I'm a bit stuck on this business project.

Let's presume you have your destination table (payments) created and
your source table is named curr_payments and that you have a sequenve
to generate your new payment_id values named payment_seq; the query is
fairly simple given the finite number of types you currently have:

insert into payments
( PaymentId,
  InvoiceID,
  PayoutType,
  PayoutAmount)
select
payment_seq.nextval,
InvoiceID,
PayoutType1,
PayoutAmount1
from curr_payments
union
select
payment_seq.currval,
InvoiceID,
PayoutType2,
PayoutAmount2
from curr_payments
union
select
payment_seq.currval,
InvoiceID,
PayoutType3,
PayoutAmount3
from curr_payments;


David Fitzjarrell

-- 
You received this message because you are subscribed to the Google
Groups "Oracle PL/SQL" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Oracle-PLSQL?hl=en

To unsubscribe from this group, send email to 
oracle-plsql+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.

Reply via email to