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

Should I use "AND" or "OR" to get the right output

$
0
0

I am querying my database for demographic information. I have several statements that are similar so if I get a couple of these with the correct syntax than I should be alright.

I would like the line below to output all Hispanic, Non -Catholic, individuals. I don't want to include nulls or "NR" (not registered) values in the output.

Here is the line I have:

SUM(CASE WHEN ethnic='H' AND (s.religion_ <>'Catholic' AND s.religion_ <> 'NR' AND s.religion_ is not null) and s.status='A' then 1 else 0 end) ,

Should the s.religion_ values use "AND" or "OR"?

Hope this makes sense


Viewing all articles
Browse latest Browse all 4871

Trending Articles



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