Solved

SQL - Update data in 5 row increments

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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSIS On fail action 5 37
t-sql need help on t-sql 10 25
VB.net Duplicating a table - primary key not created 3 31
Current Month Filter in Visual Studio 10 22
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

808 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