Solved

Updating selected record

Posted on 2013-06-18
2
189 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
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

920 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

11 Experts available now in Live!

Get 1:1 Help Now