General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 8th, 2011, 08:39 PM
beemer127 beemer127 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 1 beemer127 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Using value in 1 table to count records in another


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap