T-SQL Update table with results from Select Count

Hello all,

Trying to run a Count on a table to get the number of records the are in between 2 dates then update a record in another tabel in MS SQL2005 Express.

This code gives me an error as I am sure it is not right, but it does help to illustrate what I am trying to do.

UPDATE NRTOTALS SET nrvalue = ((SELECT COUNT(PROG_ID) FROM DPU817
WHERE (DATEDIFF(DAY, ANNIVDATE, GETDATE()) > 30) AND (DATEDIFF(DAY, ANNIVDATE, GETDATE()) < 60)
WHERE VALUENAME = 'nr3060')

Any help would be great.
panhead802Asked:
Who is Participating?
 
Chris LuttrellSenior Database ArchitectCommented:
I think you just have some ( ) out of place. See if this works, I am assuming that the Where clause belongs with the Update NRTOTALS and not with the Select.
UPDATE NRTOTALS SET nrvalue = (SELECT COUNT(PROG_ID) FROM DPU817 
WHERE (DATEDIFF(DAY, ANNIVDATE, GETDATE()) > 30) AND (DATEDIFF(DAY, ANNIVDATE, GETDATE()) < 60))
WHERE VALUENAME = 'nr3060'

Open in new window

0
 
panhead802Author Commented:
Ooops, thanks for the help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.