Quantcast
Channel: Microsoft SQL Server
Viewing all articles
Browse latest Browse all 4871

How to do SQL count with nested Case statement

$
0
0

I'm hoping someone can help me figure this statement out. This is a compliant/non compliant query for various immunizations our students have (or not).

It lists students' names, immunizations and if they are compliant (Y/N). Everything works the way it is.

select
student.lname, student.fname,
i.Description Immunization,
CASE
WHEN TotalReq -
(case when immdate1 is null then 0 else 1 end + case when immdate2 is null then 0 else 1 end + case when immdate3 is null then 0 else 1 end + case when immdate4 is null then 0 else 1 end + case when immdate5 is null then 0 else 1 end + case when immdate6 is null then 0 else 1 end + case when immdate7 is null then 0 else 1 end + case when immdate8 is null then 0 else 1 end)
<= 0
THEN 'y'
ELSE 'N'
END AS compliant
FROM student cross join immunization i left join StImmunization si on si.sno =...<= 0


Viewing all articles
Browse latest Browse all 4871

Trending Articles


Practice Sheet of Right form of verbs for HSC Students


Sarah Samis, Emil Bove III


ZARIA CUMMINGS


Need radio code for IVECO Delphi Aptiv FJ5 RBT M16


Black Angus Grilled Artichokes


Ed Sheeran – Sapphire – Pre-Single [iTunes Plus M4A]


Sunny Garcia’s Ex-Wife Colleen McCullough


99 God Status for Whatsapp, Facebook


Funeral of Sir Warwick Franklin


MHDD



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>