Solved

tsql NULL record not showing with CASE

Posted on 2013-12-16
4
280 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

856 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