• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

SQL Select

Hello,

The query below works great except when count(*) as processes is = 0 in which case it will always select 1.  How can I fix this?  When the count(*) is 1 it selects 1 as it should.

Thanks
select s.serverip, s.serverid, count(*) as processes, s.capacity 
	from servers s left outer join processqueue p on s.serverid = p.serverid 
	where(s.status = 100) 
	group by s.serverid, p.serverid, s.capacity, s.serverip 
	having count(*) < s.capacity 
	order by count(*)

Open in new window

0
grogo21
Asked:
grogo21
2 Solutions
 
Anthony PerkinsCommented:
Something like this perhaps:

select      s.serverip,
            s.serverid,
            s.capacity,
            p.processes
from      servers s
            left join (
                        Select      serverid,
                                    count(*) processes
                        From      processqueue
                        Group By
                                    serverid) p on s.serverid = p.serverid
where      s.status = 100
            And p.processes < s.capacity
order by
            p.processes
0
 
dan_nealCommented:
Or just as simple:
select s.serverip, s.serverid, count(*) as processes, s.capacity 
	from servers s left outer join processqueue p on s.serverid = p.serverid 
	where(s.status = 100) 
	group by s.serverid, p.serverid, s.capacity, s.serverip 
	having count(*) < s.capacity and count(*) > 0
	order by count(*)

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now