Solved

Updating selected record

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL SELECT query help 7 43
Inserting oldest record into new table. 5 25
Need help constructing a conditional update query 16 50
average of calculation (TSQL) 4 12
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.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
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…

825 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