Solved

tsql show record for zero count value

Posted on 2014-01-13
2
274 Views
Last Modified: 2014-01-13
I've been trying to change my join to show all Seminars, even if it has a zero count but have not been able to get this so far.  It currently only shows records in which Selected Seminars have at least one record.
SELECT        SS.SSeminarSelected SSS, COUNT(SS.SSeminarID) AS 'Seminar Count', S.RoomNumber SRN, S.Capacity Cap, S.SeminarDetails SSD, S.CumCreditsAbove30 SCCA, S.SIsActive SIA
FROM            StudentSeminars AS SS RIGHT OUTER JOIN
                         Seminars AS S ON SS.SSeminarSelected = S.SeminarID
WHERE        (S.SeminarTerm = 43) AND (SS.SSubmitTerm = 43)
GROUP BY S.RoomNumber, SS.SSeminarSelected, S.SeminarDetails, S.Capacity, S.SSort, S.CumCreditsAbove30, S.SIsActive
ORDER BY S.SSort

Open in new window

I appreciate any assistance.
0
Comment
Question by:javierpdx
2 Comments
 
LVL 24

Accepted Solution

by:
chaau earned 500 total points
ID: 39778028
Provided that seminars and studentseminars link by seminarterm column, you can rewrite your query like this:
SELECT        SS.SSeminarSelected SSS, 
COUNT(SS.SSeminarID) AS 'Seminar Count', 
S.RoomNumber SRN, 
S.Capacity Cap, 
S.SeminarDetails SSD, 
S.CumCreditsAbove30 SCCA, 
S.SIsActive SIA
FROM            Seminars AS S LEFT OUTER JOIN
                       StudentSeminars AS SS   ON SS.SSeminarSelected = S.SeminarID 
                       AND S.SeminarTerm = SS.SSubmitTerm -- this line may not even be required, comment it if it does not work
WHERE        S.SeminarTerm = 43
GROUP BY S.RoomNumber, SS.SSeminarSelected, S.SeminarDetails, S.Capacity, S.SSort, S.CumCreditsAbove30, S.SIsActive
ORDER BY S.SSort

Open in new window

0
 

Author Closing Comment

by:javierpdx
ID: 39778043
Thanks!  I appreciate the help.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server - Set Field Values ito Zero Based on Related Table 4 40
T-SQL Default value in Select? 5 38
Where on a calculated field 1 21
IIF in access query 19 24
In database programming, custom sort order seems to be necessary quite often, at least in my experience and time here at EE. Within the realm of custom sorting is the sorting of numbers and text independently (i.e., treating the numbers as number…
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

861 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