[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

tsql NULL record not showing with CASE

Posted on 2013-12-16
4
Medium Priority
?
286 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 1600 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 11

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 400 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

830 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