I have a table which have an integer coloumn. Let table name is Table1
and ColName is Col1
.
I want to add number 15 to every value in col1. what will be the sql query for this.
views:
49answers:
3
+2
A:
If you're just trying to do that via a select:
select col1 + 15 from Table1
or if you need to update the actual rows in the table:
update Table1 set col1 = col1 + 15
Justin Niessner
2010-08-24 17:20:44
This will not update the table - just getting the result...
Andreas Rehm
2010-08-24 17:22:50
@Andreas - First of all, I added an update query in case he does want to update the table. Second of all, the OP never specifies that he wants to update the table. He just said he wants the values of Col1 with 15 added to the stored value.
Justin Niessner
2010-08-24 17:24:31
+1
A:
This query updates the Col1 values in your table:
UPDATE TABLE Table1
SET Col1=Col1+15
Be carefull - if your column name contains numbers you should use this syntax:
UPDATE TABLE [Table1]
SET [Col1]=[Col1]+15
Andreas Rehm
2010-08-24 17:20:55
Unless you're using MySQL (since that's also a tag here...?) which would require the quotes to be ```...
ircmaxell
2010-08-24 17:49:02