Updating selected record

Posted on 2013-06-18
Medium Priority
Last Modified: 2013-07-03
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
Question by:Morpheus7
LVL 29

Assisted Solution

by:Kumaraswamy R
Kumaraswamy R earned 1000 total points
ID: 39256034
Update Table1
SET                 VersionNo = VersionNo + 1,
               WHERE Title = @Title


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

Accepted Solution

DBAduck - Ben Miller earned 1000 total points
ID: 39256594
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.

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
In this article, we will see two different methods to recover deleted data. The first option will be using the transaction log to identify the operation and restore it in a specified section of the transaction log. The second option is simpler and c…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

607 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