Solved

tsql NULL record not showing with CASE

Posted on 2013-12-16
4
275 Views
Last Modified: 2013-12-16
My query is not showing my NULL values.  What am I missing?  Thanks!

SELECT        AccessList.ALMYID, AccessList.FirstName, AccessList.LastName, AccessList.ClassStanding, Seminars.SeminarDetails, AccessList.TermGPA, 
                         AccessList.MYCompletedCredits, StudentSeminars.SHasAttended, StudentSeminars.SSeminarID, AccessList.CumulativeGPA, AccessList.CompletedCredits, 
                         AccessList.IsTransfer, Demographics.DEmail, 
						 CASE WHEN (StudentSignature.SSigID IS NULL) 
						 THEN 'No'
						 ELSE 'Yes'
						 END AS Signed
FROM            AccessList INNER JOIN
                         StudentSeminars ON AccessList.ALMYID = StudentSeminars.SMYID INNER JOIN
                         Seminars ON StudentSeminars.SSeminarSelected = Seminars.SeminarID INNER JOIN
                         Demographics ON StudentSeminars.SMYID = Demographics.DMYID INNER JOIN
                         StudentSignature ON StudentSeminars.SMYID = StudentSignature.SSMYID
WHERE (Seminars.SeminarID = @SeminarID)

Open in new window

0
Comment
Question by:javierpdx
4 Comments
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 400 total points
ID: 39723023
What values are null? And how do you know?

Best guess is because all your joins are inner joins which means that any rows joined on null will mean the entire row doesn't show. You need to use left joins if you want to see null values.
0
 
LVL 10

Expert Comment

by:HuaMinChen
ID: 39723078
Put a relevant value for Null column, like
isnull(col1,'')

Open in new window

0
 
LVL 13

Assisted Solution

by:magarity
magarity earned 100 total points
ID: 39723212
If there is no corresponding record at all in the StudentSignature table then you need to use LEFT OUTER JOIN for it instead of INNER JOIN.  This is what I suspect since your CASE statement is phrased correctly for NULL in that field.
0
 

Author Closing Comment

by:javierpdx
ID: 39723253
Thanks. With LEFT JOIN, the No value did show as "No".
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

758 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

20 Experts available now in Live!

Get 1:1 Help Now