Thursday 1 January 2015

Increment column value with simple update statement sql

To increment a column value in sql table with simple update statement is shown below.

DECLARE @incrementer bigint

SET @incrementer = 0

update

tablename

set @incrementer = columnname= @incrementer + 1



This can be achieved even with cursors but we all know the disadvantages of cursors in sql.

This query works even, if column is NULL.

This My first information in MyBlog - Krafting DotNet.

No comments:

Post a Comment