SQL Server query to change column value from 0 to 1

Posted on 2012-12-24
Medium Priority
Last Modified: 2012-12-25
Software: SQL Server 2005

I am looking for a query to change a specific column value from 0 to 1.

I have a table column that is always numbered 0, 1, 2, 3, etc. I want to change it so it numbers 1, 2, 3, 4 etc

Question by:dave_sky
  • 2
LVL 12

Assisted Solution

Jared_S earned 1000 total points
ID: 38719301
The syntax to set the value of the column to the value + 1 for every row is

update table1

set columnname = columnname + 1

Author Comment

ID: 38719509
Is there a syntax that will change the row value to 1........only if the value is 0?

I have existing table entries with the value of 1 which I don't want the value changed.
LVL 143

Accepted Solution

Guy Hengel [angelIII / a3] earned 1000 total points
ID: 38719961
update table1
set columnname = columnname + 1
where columnname = 0

Author Closing Comment

ID: 38720112

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question