Solved

Help Needed With Query

Posted on 2015-01-17
5
54 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
[X]
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
  • 2
  • 2
5 Comments
 
LVL 70

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 70

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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL question - help with insert for missing info 5 26
Oracle Date 6 42
debug user defined function in visual studio 2015 2 51
calculate running total 8 51
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

752 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