Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update table

Status
Not open for further replies.

WaveOut

Programmer
Sep 6, 2002
42
US
I want to write a query that will replace the contents of a column with 1 thru 162 until it replaces them all.

I have something like this:

UPDATE Craft_temp
SET craftID = id
WHERE id < 163

This replaces the first 162 items ... now I need to do the same thing 6 more times for items 163-324 and 325-487 etc ...

Dave
 
UPDATE Craft_temp
SET craftID = id
WHERE id between 163 and 324

UPDATE Craft_temp
SET craftID = id
WHERE id between 325 and 487

etc etc

or in 1 shot
UPDATE Craft_temp
SET craftID = id

why do you need to do it in sets of 162?

Denis The SQL Menace
SQL blog:
Personal Blog:
 
SQLDenis,
Thanks for the reply. I've tried what you suggested before but it did not do what I was wanting. I need row 325 to have craftID of 1. Each time the value increases greater than 162 I need to to reset to 1 again.

Dave


 
UPDATE Craft_temp
Set CraftId = Case When id % 162 = 0
Then 162
Else id % 162
End

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top