Solved

SQL - Update data in 5 row increments

Posted on 2014-04-10
2
137 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 45

Accepted Solution

by:
Kent Olsen earned 500 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

707 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