Solved

Updating selected record

Posted on 2013-06-18
2
196 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 29

Assisted Solution

by:Kumaraswamy R
Kumaraswamy R earned 250 total points
ID: 39256034
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
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.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

705 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