
August 8th, 2011, 08:39 PM
|
Registered User
|
|
Join Date: Aug 2011
Posts: 1
Time spent in forums: 16 m 30 sec
Reputation Power: 0
|
|
Using value in 1 table to count records in another
Heyas;
I am a bit stuck with a task at work.
There are two tables: CLIENTS & DOCUMENTS.
CLIENTS TABLE(ClientID, Status)
DOCUMENTS TABLE(id, clientid, created, createdby)
Here's the steps I need:
1. I need to count the number of DOCUMENTS per ClientID.
2. IF COUNT = 0
UPDATE CLIENTS
SET STATUS = 'BYPASS'
That's it...but I am stuck on it. I have tried everything I can think of, cursors, a simple UPDATE command...and nothing. I think I am just looking at this problem wrong. I was hoping someone on here would be willing to show me what I'm doing wrong.
I have even tried something like:
IF (SELECT COUNT(*) FROM DOCUMENTS WHERE ClientID = DOCUMENTS.ClientID) = 0
BEGIN
UPDATE CLIENTS
SET STATUS = 'BYPASS'
END
it didn't seem to work....can someone PLEASE help me!
|