Solved

SQL Server query to change column value from 0 to 1

Posted on 2012-12-24
4
361 Views
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.

Example:
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

Thanks!
0
Comment
Question by:dave_sky
  • 2
4 Comments
 
LVL 12

Assisted Solution

by:Jared_S
Jared_S earned 250 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
0
 

Author Comment

by:dave_sky
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.
0
 
LVL 142

Accepted Solution

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

Author Closing Comment

by:dave_sky
ID: 38720112
Thanks!
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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: …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

867 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now