Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update specific rows in sql table

I have the following SELECT statement.

SELECT     AETID, DSRID, FYEID, BASICRATE, EURORATE, 
  COMID, BRAID, CURID, CURIDCONV, ENTRYDATE, EVNUMBER, 
  ORIGIN, IEEID, RELDOCNUM, GJOID, JOURNALNUM,
  JUSTIFICATION, KEPYOAMOUNT, KEPYONUM, STATUS, 
  UPDSTATUS, TOTALCB, IDLINKED, CREUSERID, CREUSERDATE, 
  UPDUSERID, UPDUSERDATE, ACEIDCROSSENTRY, ACEIDCROSSEDENTRY, 
  ISCROSS, ISCROSSED, ACEIDCANCEL, ACEIDPRIMARY, CCEID
FROM         EliteUser.ACE
WHERE     (JOURNALNUM > 1193) 
  AND (JOURNALNUM < 2387)

What I want to do is update the specific rows so that where journalnum = 1194 updates to 1, where journalnum = 1195 updates to 2, etc

like image 861
splogo Avatar asked Dec 21 '22 10:12

splogo


1 Answers

Which column is the new value to go in? Assuming you want to update the JournalNum column so that it starts at 1:

UPDATE
    EliteUser.ACE
SET
    JournalNum = JournalNum - 1193
WHERE
    JournalNum > 1193
AND JournalNum < 2387
like image 120
Tobsey Avatar answered Jan 07 '23 03:01

Tobsey