I apologize, I think I actually do want it to overwrite values (especially the "expirydate -------------- < ----- etime"). However, like you suggested, the key for the first move should be userid because that value has to be unique. So for example if a row already exists with that userid, it should just update the rest of the field and not create a totally new entry with a duplicate userid in the "To_subscriptionlog" table.
I agree that the second move looks a lot more complicated. The only common field in "To_paymentinfo" and "To_paymenttransaction" is paymentinfoid. Would it be possible or easier to somehow create the 2 tables from the 1 independently of each other?:
e.g.
To_paymentinfo -----------< --- From_payments
paymentinfoid -------------- < --- (Generate next avaliable number in this column)
hash ----------------------- < --- (Set all to "Imported")
subscriptionid --------------- < --- (Set all to "1")
subscriptionsubid ------------ < --- ("2" IF above field mc_gross is 4, "1" IF above field mc_gross is 6, "0" IF above field mc_gross is 10)
userid ---------------------- < --- userid
completed ------------------ < --- (Set all to "0")
And once the above is created:
To_paymenttransaction --- < --- To_paymentinfo
paymenttransactionid ------- < --- (Generate next available number in this column)
paymentinfoid -------------- < --- paymentinfoid
transactionid --------------- < --- txn_id field from the "From_payments" table record where userid=userid from "To_paymentinfo"
state ---------------------- < --- (Set all to "1")
amount -------------------- < --- mc_gross field from the "From_payments" table record where userid=userid from "To_paymentinfo"
currency ------------------- < --- mc_currency field from the "From_payments" table record where userid=userid from "To_paymentinfo"
dateline -------------------- < --- payment_date field from the "From_payments" table record where userid=userid from "To_paymentinfo"
paymentapiid --------------- < --- (Set all to "1")
request -------------------- < --- (Set all to "NULL")
reversed ------------------- < --- (Set all to "0")
Its just a suggestion and I dont even know if its possible to perform such statements as above (like VLOOKUP) and reference other tables but I really don?t know much SQL besides the basic queries.
Thank you for looking in to this and all help is much appreciated.
|