tags:

views:

409

answers:

3

Hi guys, i can't do a relative simple update query in access or sql server. My simple task is: adding 1 to the current value of a column.

I'm using this syntax:

UPDATE MyTable SET ColumnA = ColumnA + 1 WHERE MyPrimaryKey= 100

But it does't work.

Someone can help me ?

Thanks bye!

A: 

Asked & answered before

Your query seems ok. Is there any error while trying to execute the query ?

Ahmet Kakıcı
I don't know.. it seem it didn't work... anyway thanks for your answer!
stighy
A: 

i think you can use a variable here.

code should be more or less:

DECLARE @MyVariable int;
SET @MyVariable = SELECT ColumnA FROM tableA WHERE PK=100; 
SET @MyVariable = @MyVariable + 1; 
UPDATE tableA SET ColumnA = @MyVariable WHERE PK=100;

it's been some time i haven't write sql but it should be something like that.

emredog
A: 

Ok guys i've solved.. my error was this:

UPDATE myTable SET Column1=Column1+1 AND Column2=Column2+2

instead

UPDATE myTable SET Column1=Column1+1 , Column2=Column2+2

I've used AND instead ,

Bye and thanks to all helped me !

Bye

stighy
Which is quite different to your original question, You should have shown 2 columns in the question and we'd have answered this in a few seconds.
gbn