Hi,
how I can do this: a=a+1 in sql server query?
Thanks!
Hi,
how I can do this: a=a+1 in sql server query?
Thanks!
If you want to increase the value of a column in a specific row, this will do it for you:
UPDATE tablename
SET columnname = columnname + 1
WHERE primarykey = id
Other than that, please specify what you mean by your question.
UPDATE TableName SET ColumnName = ColumnName + 1 WHERE WhateverYouWant = WhatEverYouNeed
You really need to provide more information... folk have given answers for updating a column; so for completeness here's how to declare, init and increment a variable:
DECLARE @a INT
SET @a = 10
SET @a = @a + 1
It's also legal to update variables in SQL 2005 using the following
declare @a int
select column1, column2, @a = @a + column3
from table
where condition
It's similar to Ahmet KAKICI's answer just using a local variable.
SQL Server 2008 introduced new T-SQL syntax for "Compound Assignment Operators"
DECLARE @price AS MONEY = 10.00;
SET @price += 2.00;
SELECT @price;