Solved

SQL - Update data in 5 row increments

Posted on 2014-04-10
2
133 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 45

Accepted Solution

by:
Kdo 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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.

777 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