Jump to content

MySQL statement - Help


defcon2000

Recommended Posts

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 CURDATE()

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,

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.