[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

T-SQL Update table with results from Select Count

Posted on 2009-04-22
2
Medium Priority
?
1,930 Views
Last Modified: 2012-05-06
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.
0
Comment
Question by:panhead802
2 Comments
 
LVL 27

Accepted Solution

by:
Chris Luttrell earned 2000 total points
ID: 24210918
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
 

Author Closing Comment

by:panhead802
ID: 31573596
Ooops, thanks for the help.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

831 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