Solved

Sql Syntax Help

Posted on 2008-06-20
2
289 Views
Last Modified: 2010-03-20
Hello, please reffer to my question here:

http://www.experts-exchange.com/Programming/Languages/SQL_Syntax/Q_23494097.html

I chose to use:
select s.serverip, p.serverid, isnull(p.processCnt ,0) processCnt
from servers s left outer join
( Select serverid, count(1) processCnt from processqueue
Group by serverid) as p
on s.serverid = p.serverid And s.status = 100
and p.processCnt <= s.capacity
order by p.processCnt

But, I found an issue with it after I closed the question.  The problem is that p.serverid is returning null when p.processCnt  returns zero.  I need it to return the ServerId and not a null value. How can I fix this?

Thanks Very Much!
0
Comment
Question by:grogo21
2 Comments
 
LVL 2

Assisted Solution

by:jgoeders
jgoeders earned 100 total points
ID: 21835326
Hmmm....it seems that your sub-query p is counting records.  If the count is 0 that means there are no records.  How will it get a serverID out of no records?
0
 

Accepted Solution

by:
grogo21 earned 0 total points
ID: 21835586
Solution:

select s.serverip, s.serverid, count(*) as processes
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(*)

Thanks!
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.

Join & Write a Comment

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now