Updating multiple rows at a time in sql server the alliance dating
For the Sales Last Year column, I increase the value by 5% by multiplying the column by 1.05.
The following table shows the results returned by the SELECT statement after I update the three columns: As you can see, updating column values is a very straightforward process when using an UPDATE statement.
The code you posted doesn't have a sub-query, and an UPDATE statement cannot be a subquery.
-- Rod at work Check out these links on how to get faster and more accurate answers: Forum Etiquette: How to post data/code on a forum to get the best help Need an Answer? You Need a Question How to Post Performance Problems Crosstabs and Pivots or How to turn rows into columns Part 1Crosstabs and Pivots or How to turn rows into columns Part 2 I know that code doesn't have a subquery, I stated that I also tried a subquery using where exists.
Note, however, that the data is slightly different in the Adventure Works database from what’s stored in the Adventure Works2008 database, so your results will be different than what is shown here. (Only the last example might need to be modified, which I’ll explain when we get to it.) To try out the examples in the article, you must first create the Sales Staff table, as shown in the following Transact-SQL code: Notice that I tag on a SELECT statement at the end of the code to retrieve the new content in the Sales Staff table.
(I also add a SELECT statement to the examples to verify the data modifications.) The SELECT statement above returns the results shown in the following table: As I mentioned above, your UPDATE statement must include a SET clause.
The WHERE clause specifies the search conditions that define which rows in the target table should be updated.
In the following UPDATE statement, I modify only the rows that have a Territory Name value of United Kingdom: As you can see, I specify in the SET clause that the Territory Name value should be changed to UK.
By using an UPDATE statement, you can modify data in individual rows, sets of rows, or all rows in a table.For the Sales Quota column, I increase the value by 50000.For the Sales YTD column, I simply specify a literal value, which in this case is 0.-- Rod at work Check out these links on how to get faster and more accurate answers: Forum Etiquette: How to post data/code on a forum to get the best help Need an Answer? You Need a Question How to Post Performance Problems Crosstabs and Pivots or How to turn rows into columns Part 1Crosstabs and Pivots or How to turn rows into columns Part 2 A single update query can update all of the rows in a table if you so desire.The fact that you're getting errors as to sub-queries is simply telling that a. you're using them in such a way that they would require a single value. How about you post what you've tried so far so that we can help you with the specific problem?