Solved

SQL Server query to change column value from 0 to 1

Posted on 2012-12-24
4
363 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 143

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
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.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

830 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