Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2002-05-22 : 10:23:54
|
| Ash writes "I have a table with fields that act as counters. What is the fastest way to perform an increment on these fields? The only way I can think of, is to perform a SELECT to get the original values, and then an UPDATE with the original value+1. I don't like this way because it's 2 db accesses. I have to do this increment on maybe 30 fields at a time, and that means 60 db accesses (yuck). What can I do? Please help me." |
|
|
JustinBigelow
SQL Gigolo
1157 Posts |
Posted - 2002-05-22 : 10:35:56
|
| What you want should require only two executions, not sixty.simplest way...update fooset field1 = field1 + 1set field2 = field2 + 1...set field30 = field30 + 1It maybe a pain in the ass to type but if you put it in a stored procedure you would only have to do it once. It also sounds like your table structure could possibly be improved to make a function like this easier. Care to share your table design?JustinEdited by - justinbigelow on 05/22/2002 10:36:39 |
 |
|
|
|
|
|