Solved

SQL - Update data in 5 row increments

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
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.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now