Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to reset the count to 0
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

19 Posts

Posted - 01/09/2014 :  03:14:10  Show Profile  Reply with Quote
I have a table with records as follows: Its just a sample table for understanding the scenario.

Create table resetcount
userid int,
totalhighprtjobs int,
[date] datetime

insert into resetcount Values (147,0,GETDATE())
insert into resetcount Values (169,1,GETDATE())
insert into resetcount Values (176,0,GETDATE())
insert into resetcount Values (187,1,GETDATE())
insert into resetcount Values (188,1,GETDATE())

Everytime when i assign a job to a userid the totalhighprtjobs gets increased by will assign to all the users randomly and equally. Suppose if all the count of totalhighprtjpbs becomes 1 then i want to reset all those to 0.if suppose today there are 3 jobs assigned to useids 169,187,188.tomorrow while assigning jobs since the count of highprtjobs of userid 147 and 176 are 0 first these two will be assigned a job.After assigning to these two the count ot totalhighprtjobs wil be 1 for all,then i want to reset the count to 0 for all after assigning to those two.

Can you guide me in this ..

Yak Posting Veteran

75 Posts

Posted - 01/09/2014 :  04:31:34  Show Profile  Reply with Quote
do you mean that execute the following after assigning?


--if all records are assigned, reset.
UPDATE resetcount
SET totalhighprtjobs = 0
FROM resetcount
WHERE totalhighprtjobs = 0)

From Japan
Sorry, my English ability is limited.
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 01/09/2014 :  05:01:48  Show Profile  Reply with Quote
sounds like a simple update to me

update resetcount
set totalhighprtjobs = 0
where totalhighprtjobs > 1
and date < GETDATE()

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.04 seconds. Powered By: Snitz Forums 2000