Solved

Updating selected record

Posted on 2013-06-18
2
188 Views
Last Modified: 2013-07-03
Hi,
I am using the code below to update an entry in a table.  There are multiple fields in the table with the same Title but I only want to change the VersionNo field for the entry I am adding

Update Table1
SET             Title = @Title,
        VersionNo = VersionNo + 1,
                  Date = GETDATE(),
              AuthBy = @AuthBy,
              Reason = @Reason
WHERE Title = @Title


Any help would be appreciated.

Many thanks
0
Comment
Question by:Morpheus7
2 Comments
 
LVL 29

Assisted Solution

by:Kumaraswamy R
Kumaraswamy R earned 250 total points
Comment Utility
Update Table1
SET                 VersionNo = VersionNo + 1,
               WHERE Title = @Title


SQL UPDATE Syntax
 

UPDATE table_name
 SET column1=value1,column2=value2,...
 WHERE some_column=some_value;
0
 
LVL 24

Accepted Solution

by:
DBAduck - Ben Miller earned 250 total points
Comment Utility
You have to have another key to differentiate from the other titles that are the same.  there is really no other way to do the update because the Where clause limits the rows that get updated.

Hopefully you have another key to add to title that makes the rows unique, otherwise I would suggest an alternate key approach by adding something like an Identity column to your table so that you have a unique key to allow you to update one specific row.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In this article I will describe the Detach & Attach 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.
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.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

772 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

10 Experts available now in Live!

Get 1:1 Help Now