[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SQL - Update data in 5 row increments

Posted on 2014-04-10
2
Medium Priority
?
144 Views
Last Modified: 2014-04-10
I need up update some data in an internal table.  It is the state field.  My result set is 100 rows.

I want to update the first 5 with TX
The next five with DE
The next five with CA

Then start again with TX and continue until i've gone through all 100 rows.

Thanks
0
Comment
Question by:CipherIS
2 Comments
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 2000 total points
ID: 39992431
Do you have an identity column?  If so, that's the easiest.

UPDATE mytable
SET state = case when (ID / 5) % 3 = 0 then 'TX'
                 when (ID / 5) % 3 = 1 then 'DE'
                 else 'CA'
            end

Open in new window


Good Luck,
Kent
0
 
LVL 1

Author Closing Comment

by:CipherIS
ID: 39992657
Thanks
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
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…
Suggested Courses

829 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