views:

49

answers:

3

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.

+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
This will not update the table - just getting the result...
Andreas Rehm
@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
+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
Unless you're using MySQL (since that's also a tag here...?) which would require the quotes to be ```...
ircmaxell
+1  A: 
UPDATE Table1 SET Col1 = (Col1 + 15)
Eton B.