SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 update by 5%
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

aboyse
Starting Member

12 Posts

Posted - 07/12/2013 :  06:34:37  Show Profile  Reply with Quote
How do you update prices by 5%

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 07/12/2013 :  06:44:09  Show Profile  Reply with Quote
do you mean increment prices by 5 %? if yes,

UPDATE Table
Price = Price  + (Price * .05)


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs

Edited by - visakh16 on 07/12/2013 06:47:41
Go to Top of Page

bitsmed
Constraint Violating Yak Guru

405 Posts

Posted - 07/12/2013 :  06:46:58  Show Profile  Reply with Quote
price=price*1.05
Go to Top of Page

aboyse
Starting Member

12 Posts

Posted - 07/12/2013 :  06:50:35  Show Profile  Reply with Quote
Tried that and this error came back at me... Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Queries and reconnect.
Go to Top of Page

bitsmed
Constraint Violating Yak Guru

405 Posts

Posted - 07/12/2013 :  06:54:39  Show Profile  Reply with Quote
lets say your primarykey column is called id, then use this:

update table
   set price=price*1.05
 where id>0

Edited by - bitsmed on 07/12/2013 06:55:19
Go to Top of Page

aboyse
Starting Member

12 Posts

Posted - 07/12/2013 :  06:59:22  Show Profile  Reply with Quote
still got back the same error...
Go to Top of Page

bitsmed
Constraint Violating Yak Guru

405 Posts

Posted - 07/12/2013 :  07:05:37  Show Profile  Reply with Quote
Please post the table design.

ps. I have never come across this error using mssql, only when using mysql.
Go to Top of Page

aboyse
Starting Member

12 Posts

Posted - 07/12/2013 :  07:11:36  Show Profile  Reply with Quote
roomNo = Int(11)
hotelNo = Int(11)
type = varchar(45)
price = varchar(45)
Go to Top of Page

bitsmed
Constraint Violating Yak Guru

405 Posts

Posted - 07/12/2013 :  07:16:04  Show Profile  Reply with Quote
I'm guessing the primary key is roomNo and hotelNo. Is this correct?
If so, try this:

update table
   set price=price*1.05
 where roomNo>0
   and hotelNo>0
Go to Top of Page

bitsmed
Constraint Violating Yak Guru

405 Posts

Posted - 07/12/2013 :  07:18:02  Show Profile  Reply with Quote
woops!
Is Price field varchar?
You cannot calculate on alphanumeric fields.
Go to Top of Page

aboyse
Starting Member

12 Posts

Posted - 07/12/2013 :  07:23:00  Show Profile  Reply with Quote
That was grand all of them changes worked...
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000