Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > MySQL > Alter many cols in table with 1 command (and some maths)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-03-04, 09:45
damalo damalo is offline
Registered User
 
Join Date: Apr 2004
Posts: 12
Exclamation Alter many cols in table with 1 command (and some maths)

Hi all,

so i currently have a table with products in it. Each product contains 12 units. The prices i have in my db include some tax at 21%. As a special offer i want to sell a product item(12 units) at the price of 11 units.

So is there some way i can query the db and tell it to calculate the price of 1 unit and then 11 and then VAT for that 11 and update all prices.

I would do it on a checkout page but the catalog is db driven so i would like prices to be changed there also.

Any ideas guys?

Cheers,
damalo
Reply With Quote
  #2 (permalink)  
Old 06-03-04, 09:55
Pat Phelan Pat Phelan is online now
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 9,573
Can you give us an example showing what you've got now, and what you want to get out of it?

-PatP
Reply With Quote
  #3 (permalink)  
Old 06-03-04, 09:59
damalo damalo is offline
Registered User
 
Join Date: Apr 2004
Posts: 12
sure,

so like so....

ID Product price
------- -------- -------
1 product1 $120

The above price is for 12 units with 21% tax included. I want to store a price for 11 of these units. So to get this...

120 / 12 = 10 (10$ for 1 unit and 21% tax)

11 units = $10 x 11 = $110

this new price is then sotred in the db.

Thanks again!
damalo
Reply With Quote
  #4 (permalink)  
Old 06-03-04, 10:03
Pat Phelan Pat Phelan is online now
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 9,573
That is a lot simpler than what I thought you meant. I'd just multiply by 11.0 / 12 and be done with it.

-PatP
Reply With Quote
  #5 (permalink)  
Old 06-03-04, 10:08
damalo damalo is offline
Registered User
 
Join Date: Apr 2004
Posts: 12
Red face

came up with this...


update products set price =( (price / 12) * 11 ) where id = 1;


looks like its the business!

Cheers!
(i think i confused myself there a bit aswell hehe)

damalo
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

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