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 > Database Server Software > MySQL > MySQL Statement - HELP

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-05-06, 04:46
defcon2000 defcon2000 is offline
Registered User
 
Join Date: Dec 2005
Posts: 5
MySQL Statement - HELP

Hello Everyone,

I want to insert a new record with data from 2 tables, based on a condition from a table . The insert should be as follows:

INSERT INTO subscriptiontrans (subscriptiontrans_id, subscription_id,
datecreated, paymentdue,
datepaid, subscriptiontype_id,
subscriptiondescription, service_description,
occurence, occurencetype,
currencysymbol, amount, amountlocal, amountdiscount,
amounttax, amountnet, subscriptiontrans_status, printed)
VALUES (????????????)

The tables to get data from are as follows:
--------------------------------------------------
Table name: subscription
`subscription_id`
`customer_id`
`datecreated`
`datedue`
`subscriptiontype_id`
`amountdiscount`
`specialnotes`
`subscription_status`
--------------------------------------------------
Table name: subscriptiontype
`subscriptiontype_id`
`subscription_type`
`subscriptiondescription`
`occurence`
`occurencetype`
`currency_id`
`amount`
`taxpercent`
`subscriptiontype_status`
--------------------------------------------------
Table name: currency
`currency_id`
`currency`
`currencysymbol`
`rate`
--------------------------------------------------

The conditions for insert should be as follows:

subscription.datedue = CURDATE()
subscription.subscription_status = 'Active'

The following are calculations and defaults:

subscription_id = subscription.subscription_id
datecreated = CURDATE()
paymentdue = 7 days from
datepaid = NULL
subscriptiontype_id = subscriptiontype.subscriptiontype_id
subscriptiondescription = subscriptiontype.subscriptiondescription
service_description = subscriptiontype.service_description
occurence = subscriptiontype.occurence
occurencetype = subscriptiontype.occurencetype
currencysymbol = currency.currencysymbol
amount = subscriptiontype.amount
amountlocal = currency.rate * subscriptiontype.amount
amountdiscount = subscription.amountdiscount
amountnet = (amountlocal - amountdiscount) * ((100 - amounttax)/100)
subscriptiontrans_status = 'Unpaid'
printed = 'N'

Thanks in advance for your help.

Rgds,
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