Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Help Needed With Query

Posted on 2015-01-17
5
52 Views
Last Modified: 2015-01-20
I need help with one more Query and then I'm done.  For this one, I need to update the SinceLastAssigned value for every participant who has a value of zero to the MAX value in that column, plus one (in the case of the data presented, that would be 176).  Please let me know if you have any questions.  Appreciate the help!

Sample Data
0
Comment
Question by:penlandt
  • 2
  • 2
5 Comments
 
LVL 69

Expert Comment

by:Qlemo
ID: 40556036
Is 176 the value for all rows having a zero?
0
 
LVL 1

Author Comment

by:penlandt
ID: 40556248
Yes, that's correct.   I'm assuming that this can be done in one query but the first part (of course) has to be identifying the maximum value in the since last assigned column, then updating all the rows where the value is 0 to that maximum value plus one.  Hope that helps.
0
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40556285
That's easy. If you would need unique values, that's getting difficult ;-).
update  tbl set sinceLastAssigned = nextMaxAssigned
from (select max(sinceLastAssigned)+1 as nextMaxAssigned from tbl) m
where sinceLastAssigned = 0

Open in new window

0
 
LVL 15

Expert Comment

by:Vikas Garg
ID: 40557191
Hi,

I agree with Qlemo,

You can Update
Update Tbl set sinceLastAssigned = (SELECT max(sinceLastAssigned) from Tbl)  +1
WHERE sinceLastAssigned = 0

Open in new window

0
 
LVL 1

Author Closing Comment

by:penlandt
ID: 40561404
Thank you very much, this was exactly what I needed!
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

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