Solved

Help Needed With Query

Posted on 2015-01-17
5
48 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 68

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 68

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 14

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now