We help IT Professionals succeed at work.

Looping and updating records

kloner
kloner asked
on
163 Views
Last Modified: 2012-08-13
Hi all,

I have gone blank!

I have a table of candidates, and in this table a DAYS_LAST_CONTACTED column. I also have a table called candidate_notes, and there are M:1 notes per candidate.

What I am trying to do, is create a nightly job, that loops through all candidates and populates the DAYS_LAST_CONTACTED field with ... you guessed it ... the last time (in days) when a candidate was contacts.

Am I right to say I should somehow SELECT all the candidates, and then somehow do a select on the NOTES table, and get the most recent date and calculate the diff??

Eg: To get the date diff for a candidate...

CAST(DATEDIFF(DD, (SELECT TOP 1 N.[DateLogged] FROM [TBL_BLUECARE_CANDIDATES_NOTES] N WHERE N.[EXT_REF_ID] = C.[EXT_REF_ID] ORDER BY N.[DateLogged] DESC), getDate()) AS INT)

Would be grateful for a solution.

Cheers EE!

SELECT [EXT_REF_ID] (PK)
      ,[Title]
      ,[First Name]
      ,[Surname]
      ,[Mobile]
      ,[Email]
      ,[Postcode]
      ,[DaysLastContacted]
FROM [TBL_BLUECARE_CANDIDATES]
 
 
SELECT [EXT_REF_ID] (FK)
      ,[DateLogged]
      ,[Initials]
      ,[Notes]
  FROM [TBL_BLUECARE_CANDIDATES_NOTES]

Open in new window

Comment
Watch Question

Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thank you so much for your help!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.